/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package mainpackage;
//#if NOKIA=="TRUE"  
//# //import com.nokia.mid.ui.DirectUtils;
//#endif
import engine.goods.Goods;
import java.util.Hashtable;
import java.util.Random;
import java.util.Vector;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;


/**
 *
 * @author lenovo
 */
public class Tools {

	private static Image alphaBG; 
	public static final void drawAlphaBG(Graphics g) {
		if (alphaBG == null) {
//			alphaBG = Image.createImage(100, 100);
//			Graphics g1 = alphaBG.getGraphics();
			int len = 100*100;
			int[] rgbData = new int[len];
			for (int i=0;i<len;i++) {
				rgbData[i] = 0x7f000000;
			}
			alphaBG = Image.createRGBImage(rgbData, 100, 100, true);
//			g1.drawRGB(rgbData, 0, 100, 0, 0, 100, 100, true);
		}
		int w=0,h=0;
		for (int i=0;i<640;i += 100) {
			for (int j=0;j<360;j+=100) {
				g.drawImage(alphaBG, j, i, Graphics.LEFT|Graphics.TOP);
			}
		}
		
	}
	
    /**
     * 绘制一条蓝色的选中线
     * @param g
     * @param direction 方向（1：向上，2：向下）
     * @param mask  选择条的图片
     * @param startX 线开始的位置，以黑线为准
     * @param startY
     * @param width  选择条的宽度
     */
    public static void drawSelectMask(Graphics g, byte direction, Image mask, int startX, int startY, int width) {
        if (mask == null) {
            return;
        }
        setColor(g, 0x455759);
        g.drawLine(startX, startY, startX + width, startY);
        if (direction == 1) {
            drawTilePic(g, (byte) 1, startX, startY - 23, width, mask, 0, 0, 8, 23, Constant.TRANS_NONE);
        } else {
            drawTilePic(g, (byte) 1, startX, startY + 1, width, mask, 0, 0, 8, 23, Constant.TRANS_ROT180);
        }
    }

    /**
     * 绘制一条蓝色的选中线,以及选着线上图片文字内容
     * @param g
     * @param direction  方向（1：向上，2：向下）
     * @param mask  选择条的图片
     * @param startX   线开始的位置，以黑线为准
     * @param startY
     * @param width   选择条宽度
     * @param arrow   箭头图片
     * @param buttonLeft   左边的button图片
     * @param imgLeftStartX  左边button在图片上开始的位置
     * @param imgLeftStartY
     * @param buttonLeftW      左边button宽度
     * @param buttonLeftH      左边button高度
     * @param buttonRight      右边的button
     * @param imgRightStartX   右边的button图片上开始的位置
     * @param imgRightStartY
     * @param buttonRightW     右边的button宽度
     * @param buttonRightH     右边button高度
     */
    public static void drawSelectMask(Graphics g, byte direction, Image mask, int startX, int startY, int width, Image arrow, Image buttonLeft, int imgLeftStartX, int imgLeftStartY, int buttonLeftW, int buttonLeftH, Image buttonRight, int imgRightStartX, int imgRightStartY, int buttonRightW, int buttonRightH) {
    	if (true)
    		return;
        int iStartY = direction == 1 ? startY - 7 - buttonLeftH : startY + 7;
        if (buttonLeft != null) {
            g.drawRegion(buttonLeft, imgLeftStartX, imgLeftStartY, buttonLeftW, buttonLeftH, Constant.TRANS_NONE, startX + 8, iStartY, 0);
            if (arrow != null) {
                drawArrow(g, arrow, (byte) 2, startX + 15 + buttonLeftW, iStartY + ((buttonLeftH - 7) >> 1));
            }
        }
        if (buttonRight != null) {
            g.drawRegion(buttonRight, imgRightStartX, imgRightStartY, buttonRightW, buttonRightH, Constant.TRANS_NONE, startX + width - 8 - buttonRightW, iStartY, 0);
            if (arrow != null) {
                drawArrow(g, arrow, (byte) 1, startX + width - 20 - buttonRightW, iStartY + ((buttonRightH - 7) >> 1));
            }
        }
        drawSelectMask(g, direction, mask, startX, startY, width);
    }

    /**
     * 绘制圆矩形的图形边框 
     * @param g  
     * @param startX 开始位置
     * @param startY
     * @param border  边框图片
     * @param w  宽度
     * @param h  高度
     */
    public static void drawRoundRectBorder(Graphics g, Image border, int w, int h, int startX, int startY) {
        //#if NOKIA_S60V5
         g.drawRegion(border, 0, 0, 13, 13, Constant.TRANS_NONE, startX, startY, 0); //左上角
         g.drawRegion(border, 0, 0, 13, 13, Constant.TRANS_ROT90, startX + w - 13, startY, 0); //右上角
         g.drawRegion(border, 0, 14, 13, 13, Constant.TRANS_NONE, startX, startY + h - 13, 0); //左下角
         g.drawRegion(border, 0, 14, 13, 13, Constant.TRANS_ROT270, startX + w - 13, startY + h - 13, 0); //右下角
         drawTilePic(g, (byte) 1, startX + 13, startY, w - 26, border, 28, 0, 13, 13, Constant.TRANS_NONE);//上面
         drawTilePic(g, (byte) 1, startX + 13, startY + h - 13, w - 26, border, 14, 14, 13, 13, Constant.TRANS_NONE);//下面
         //左面
         drawTilePic(g, (byte) 2, startX, startY + 13, h - 26, border, 14, 0, 13, 13, Constant.TRANS_NONE);
         //右面
         drawTilePic(g, (byte) 2, startX + w - 13, startY + 13, h - 26, border, 14, 0, 13, 13, Constant.TRANS_ROT180);
        //#else
//#        //先绘制四个角
//#        g.drawRegion(border, 0, 0, 7, 7, Constant.TRANS_NONE, startX, startY, 0); //左上角
//#        g.drawRegion(border, 7, 0, 7, 7, Constant.TRANS_NONE, startX + w - 7, startY, 0); //右上角
//#        g.drawRegion(border, 0, 7, 7, 7, Constant.TRANS_NONE, startX, startY + h - 7, 0); //左下角
//#        g.drawRegion(border, 7, 7, 7, 7, Constant.TRANS_NONE, startX + w - 7, startY + h - 7, 0); //右下角
//#        //绘制四周的边框
//#        //上面的边框
//#        drawTilePic(g, (byte) 1, startX + 7, startY, w - 14, border, 21, 0, 6, 7, Constant.TRANS_NONE);
//#        //下面
//#        drawTilePic(g, (byte) 1, startX + 7, startY + h - 7, w - 14, border, 21, 7, 6, 7, Constant.TRANS_NONE);
//#        //左面
//#        drawTilePic(g, (byte) 2, startX, startY + 7, h - 14, border, 14, 0, 7, 7, Constant.TRANS_NONE);
//#        //右面
//#        drawTilePic(g, (byte) 2, startX + w - 7, startY + 7, h - 14, border, 14, 7, 7, 7, Constant.TRANS_NONE);
        //#endif
    }

    /**
     * 绘制圆角矩形的四个角
     * @param g
     * @param border 圆角图片
     * @param byType //类型(1左上角,2右上角,3左下角,4右下角.5上边框,6下边框,7左边框,8右边框)
     * @param w
     * @param h
     * @param startX //矩形的开始位置
     * @param startY 
     */
    public static void drawFrameCorner(Graphics g, Image border, byte byType, int w, int h, int startX, int startY) {
        //#if NOKIA_S60V5
         switch (byType) {
             case 1:
                 g.drawRegion(border, 0, 0, 13, 13, Constant.TRANS_NONE, startX, startY, 0); //左上角
                 break;
             case 2:
                 g.drawRegion(border, 0, 0, 13, 13, Constant.TRANS_ROT90, startX + w - 13, startY, 0); //右上角
                 break;
             case 3:
                 g.drawRegion(border, 0, 14, 13, 13, Constant.TRANS_NONE, startX, startY + h - 13, 0); //左下角
                 break;
             case 4:
                 g.drawRegion(border, 0, 14, 13, 13, Constant.TRANS_ROT270, startX + w - 13, startY + h - 13, 0); //右下角
                 break;
             case 5://上面
                 drawTilePic(g, (byte) 1, startX + 13, startY, w - 26, border, 28, 0, 13, 13, Constant.TRANS_NONE);//上面
             case 6://下面
                 drawTilePic(g, (byte) 1, startX + 13, startY + h - 13, w - 26, border, 14, 14, 13, 13, Constant.TRANS_NONE);//下面
             case 7:
                 //左面
                 drawTilePic(g, (byte) 2, startX, startY + 13, h - 26, border, 14, 0, 13, 13, Constant.TRANS_NONE);
             case 8:
                 //右面
                 drawTilePic(g, (byte) 2, startX + w - 13, startY + 13, h - 26, border, 14, 0, 13, 13, Constant.TRANS_ROT180);
                 break;
         }
        //#else
//#        switch (byType) {
//#            case 1:
//#                g.drawRegion(border, 0, 0, 7, 7, Constant.TRANS_NONE, startX, startY, 0); //左上角
//#                break;
//#            case 2:
//#                g.drawRegion(border, 7, 0, 7, 7, Constant.TRANS_NONE, startX + w - 7, startY, 0); //右上角
//#                break;
//#            case 3:
//#                g.drawRegion(border, 0, 7, 7, 7, Constant.TRANS_NONE, startX, startY + h - 7, 0); //左下角
//#                break;
//#            case 4:
//#                g.drawRegion(border, 7, 7, 7, 7, Constant.TRANS_NONE, startX + w - 7, startY + h - 7, 0); //右下角
//#                break;
//#            case 5:
//#                drawTilePic(g, (byte) 1, startX + 7, startY, w - 14, border, 21, 0, 6, 7, Constant.TRANS_NONE);//上面
//#            case 6:
//#                drawTilePic(g, (byte) 1, startX + 7, startY + h - 7, w - 14, border, 21, 7, 6, 7, Constant.TRANS_NONE);//下面
//#            case 7:
//#                //左面
//#                drawTilePic(g, (byte) 2, startX, startY + 7, h - 14, border, 14, 0, 7, 7, Constant.TRANS_NONE);
//#            case 8:
//#                //右面
//#                drawTilePic(g, (byte) 2, startX + w - 7, startY + 7, h - 14, border, 14, 7, 7, 7, Constant.TRANS_NONE);
//#                break;
//#        }
        //#endif
    }

    /**
     * 绘制圆矩形,带有透明度，中间用图片填充
     * @param g
     * @param framePic  边框图片
     * @param bgPic  背景中的填充图片
     * @param fillDirection   背景填充方向
     * @param w   宽度
     * @param h  高度
     * @param startX
     * @param startY
     */
    public static void drawRoundRect(Graphics g, Image framePic, Image bgPic, byte fillDirection, int w, int h, int startX, int startY) {
        //绘值物品和宝石的背景
        //绘制最外层的提示框
        //填充中间的部分
        if (fillDirection == 1) {
            //横向的填充
            //#if NOKIA_S60V5
             drawTilePic(g, (byte) 1, startX + 13, startY + 13, w - 26, bgPic, 0, 0, bgPic.getWidth(), h - 26, Constant.TRANS_NONE);
            //#else
//#            drawTilePic(g, (byte) 1, startX + 7, startY + 7, w - 14, bgPic, 0, 0, 10, h - 14, Constant.TRANS_NONE);
            //#endif
        } else if (fillDirection == 2) {
            //纵向的填充
            //#if NOKIA_S60V5
             drawTilePic(g, (byte) 2, startX + 13, startY + 13, h - 26, bgPic, 0, 0, w - 26, bgPic.getHeight(), Constant.TRANS_NONE);
            //#else
//#            drawTilePic(g, (byte) 2, startX + 7, startY + 7, h - 14, bgPic, 0, 0, w - 14, 10, Constant.TRANS_NONE);
            //#endif
        }
        drawRoundRectBorder(g, framePic, w, h, startX, startY);
    }

    /**
     * 绘制翻页翻页
     * @param g
     * @param totalPage  总的页数
     * @param currentPage //当前页数
     * @param numPic  //数字图片(大数字图片)
     * @param ArrowPic //箭头图片
     * @param startX //绘制开始X位置
     * @param startY //绘制开始Y位置
     */
    public static void drawPage(Graphics g, short totalPage, short currentPage, Image numPic, Image ArrowPic, int startX, int startY) {
        String temp;
        byte byNum;
        if (currentPage == 1) {
            drawArrow(g, ArrowPic, (byte) 9, startX, startY + 1);
        } else {
            drawArrow(g, ArrowPic, (byte) 5, startX, startY + 1);
        }
        startX = startX + 10;
        if (currentPage < 10) {
            temp = "0" + String.valueOf(currentPage);
        } else {
            temp = String.valueOf(currentPage);
        }
        for (byte i = 0; i < temp.length(); i++) {
            byNum = Byte.parseByte(temp.substring(i, i + 1));
            g.drawRegion(numPic, byNum * 7, 0, 7, 9, Constant.TRANS_NONE, startX, startY, 0);
            startX = startX + 6;
        }
        //反斜线
        g.drawRegion(numPic, 150, 0, 5, 9, Constant.TRANS_NONE, startX, startY, 0);
        startX = startX + 5;
        if (totalPage < 10) {
            temp = "0" + String.valueOf(totalPage);
        } else {
            temp = String.valueOf(totalPage);
        }
        for (byte i = 0; i < temp.length(); i++) {
            byNum = Byte.parseByte(temp.substring(i, i + 1));
            g.drawRegion(numPic, 70 + byNum * 7, 0, 7, 9, Constant.TRANS_NONE, startX, startY, 0);
            startX = startX + 6;
        }
        startX = startX + 5;
        if (currentPage == totalPage) {
            drawArrow(g, ArrowPic, (byte) 10, startX, startY + 1);
        } else {
            drawArrow(g, ArrowPic, (byte) 6, startX, startY + 1);
        }
    }

    /**
     * 获得翻页字符串的宽度
     * @param totalPage  总的页数
     * @param currentPage 当前页数
     * @return
     */
    public static short getPageStrWidth(short totalPage, short currentPage) {
        byte num = (byte) (String.valueOf(totalPage).length() > 1 ? String.valueOf(totalPage).length() : String.valueOf(totalPage).length() + 1);
        num = (byte) (num + (String.valueOf(currentPage).length() > 1 ? String.valueOf(currentPage).length() : String.valueOf(currentPage).length() + 1));
        return (short) (num * 6 + 25);
    }

    /**
     * 绘制圆矩形,带有透明度，中间用颜色
     * @param g
     * @param startX
     * @param startY
     * @param bgColor  中间填充的颜色
     * @param w   宽度
     * @param h  高度
     */
    public static void drawRoundRect(Graphics g, Image framePic, int bgColor, int w, int h, int startX, int startY) {
        setColor(g, bgColor);
        //#if NOKIA_S60V5
         g.fillRect(startX + 13, startY + 13, w - 26, h - 26);
        //#else
//#        g.fillRect(startX + 7, startY + 7, w - 14, h - 14);
        //#endif
        //填充中间的部分
        drawRoundRectBorder(g, framePic, w, h, startX, startY);
    }

    /**
     * 绘制圆矩形,带有透明度，中间用图片填充
     * @param g
     * @param startX
     * @param startY
     * @param bgColor  中间填充的颜色
     * @param w   宽度
     * @param h  高度
     */
    public static void drawRoundRect(Graphics g, Image framePic, Image bgPic, byte fillDirection, int bgPicSrcX, int bgPicSrcY, int bgPicW, int bgPicH, int w, int h, int startX, int startY) {
        if (fillDirection == 1) {
            //#if NOKIA_S60V5
             drawTilePic(g, (byte) 1, startX + 13, startY + 13, w - 26, bgPic, bgPicSrcX, bgPicSrcY, bgPicW, bgPicH, Constant.TRANS_NONE);
            //#else
//#            drawTilePic(g, (byte) 1, startX + 7, startY + 7, w - 14, bgPic, bgPicSrcX, bgPicSrcY, bgPicW, bgPicH, Constant.TRANS_NONE);
            //#endif
        } else {
            //#if NOKIA_S60V5
             drawTilePic(g, (byte) 2, startX + 13, startY + 13, h - 26, bgPic, bgPicSrcX, bgPicSrcY, bgPicW, bgPicH, Constant.TRANS_ROT180);
            //#else
//#            drawTilePic(g, (byte) 2, startX + 7, startY + 7, h - 14, bgPic, bgPicSrcX, bgPicSrcY, bgPicW, bgPicH, Constant.TRANS_ROT180);
            //#endif
        }
        //填充中间的部分
        drawRoundRectBorder(g, framePic, w, h, startX, startY);
    }

    /**
     * 设置颜色(防止重复设置)
     * @param g
     * @param color 要设置的颜色值
     */
    public static void setColor(Graphics g, int color) {
        if (g.getColor() != color) {
            g.setColor(color);
        }
    }

    /**
     * 绘制箭头
     * @param g
     * @param arrowImg  箭头的图片
     * @param byType  箭头类型(蓝色:1左2右3上4下,白色:5左6右7上8下,灰色：9左10右,11上12下)
     * @param iStartX
     * @param iStartY
     */
    public static void drawArrow(Graphics g, Image arrowImg, byte byType, int iStartX, int iStartY) {
        switch (byType) {
            case 1:
                g.drawRegion(arrowImg, 12, 0, 5, 7, Constant.TRANS_NONE, iStartX, iStartY, 0);
                break;
            case 2:
                g.drawRegion(arrowImg, 12, 0, 5, 7, Constant.TRANS_MIRROR, iStartX, iStartY, 0);
                break;
            case 3:
                g.drawRegion(arrowImg, 0, 5, 7, 5, Constant.TRANS_NONE, iStartX, iStartY, 0);
                break;
            case 4:
                g.drawRegion(arrowImg, 0, 5, 7, 5, Constant.TRANS_ROT180, iStartX, iStartY, 0);
                break;
            case 5:
                g.drawRegion(arrowImg, 7, 0, 5, 7, Constant.TRANS_NONE, iStartX, iStartY, 0);
                break;
            case 6:
                g.drawRegion(arrowImg, 7, 0, 5, 7, Constant.TRANS_MIRROR, iStartX, iStartY, 0);
                break;
            case 7:
                g.drawRegion(arrowImg, 0, 0, 7, 5, Constant.TRANS_NONE, iStartX, iStartY, 0);
                break;
            case 8:
                g.drawRegion(arrowImg, 0, 0, 7, 5, Constant.TRANS_ROT180, iStartX, iStartY, 0);
                break;
            case 9:
                g.drawRegion(arrowImg, 17, 0, 5, 7, Constant.TRANS_NONE, iStartX, iStartY, 0);
                break;
            case 10:
                g.drawRegion(arrowImg, 17, 0, 5, 7, Constant.TRANS_MIRROR, iStartX, iStartY, 0);
                break;
            case 11:
                g.drawRegion(arrowImg, 17, 0, 5, 7, Constant.TRANS_ROT90, iStartX, iStartY, 0);
                break;
            case 12:
                g.drawRegion(arrowImg, 17, 0, 5, 7, Constant.TRANS_MIRROR_ROT90, iStartX, iStartY, 0);
                break;
        }
    }

    /**
     * 绘制箭头
     * @param g
     * @param arrowImg  箭头的图片
     * @param byType  箭头类型(蓝色:1左2右3上4下,白色:5左6右7上8下,灰色：9左10右)
     * @param iStartX
     * @param iStartY
     */
    public static void drawBigArrow(Graphics g, Image arrowImg, byte byType, int iStartX, int iStartY) {
        switch (byType) {
            case 1:
                g.drawRegion(arrowImg, 22, 0, 9, 13, Constant.TRANS_NONE, iStartX, iStartY, 0);
                break;
            case 2:
                g.drawRegion(arrowImg, 22, 0, 9, 13, Constant.TRANS_MIRROR, iStartX, iStartY, 0);
                break;
            case 3:
                g.drawRegion(arrowImg, 0, 9, 13, 9, Constant.TRANS_NONE, iStartX, iStartY, 0);
                break;
            case 4:
                g.drawRegion(arrowImg, 0, 9, 13, 9, Constant.TRANS_ROT180, iStartX, iStartY, 0);
                break;
            case 5:
                g.drawRegion(arrowImg, 13, 0, 9, 13, Constant.TRANS_NONE, iStartX, iStartY, 0);
                break;
            case 6:
                g.drawRegion(arrowImg, 13, 0, 9, 13, Constant.TRANS_MIRROR, iStartX, iStartY, 0);
                break;
            case 7:
                g.drawRegion(arrowImg, 0, 0, 13, 9, Constant.TRANS_NONE, iStartX, iStartY, 0);
                break;
            case 8:
                g.drawRegion(arrowImg, 0, 0, 13, 9, Constant.TRANS_ROT180, iStartX, iStartY, 0);
                break;
            case 9:
                g.drawRegion(arrowImg, 31, 0, 9, 13, Constant.TRANS_NONE, iStartX, iStartY, 0);
                break;
            case 10:
                g.drawRegion(arrowImg, 31, 0, 9, 13, Constant.TRANS_MIRROR, iStartX, iStartY, 0);
                break;
            default:
                break;
        }
    }

    /**
     * 绘制弹出操作菜单层
     * @param g   
     * @param sOpArray  菜单数组
     * @param byAlign  对齐方式(1,居中对齐,2,左对齐,3右对齐)
     * @param width   菜单的宽度
     * @param lineHeight 单个选项的高度(最小为文字高度)
     * @param bgBolor 菜单的背景颜色
     * @param fontColor  字体颜色
     * @param selectedColor  被选中后的颜色
     * @param bySelectIndex  当前选择索引
     * @param startX   开始位置
     * @param startY 
     */
    public static void drawPopMenu(Graphics g, String[] sOpArray, byte byAlign, int width, int lineHeight, int bgBolor, int fontColor, int selectedColor, byte bySelectIndex, int startX, int startY) {
        lineHeight = lineHeight < Constant.FONT_SMALL_HEIGHT ? Constant.FONT_SMALL_HEIGHT : lineHeight;
        int height = lineHeight * sOpArray.length + 10;
        //#if NOKIA_S60V5
         height = height < 41 ? 41 : height;
        //#else
//#        height = height < 31 ? 31 : height;
        //#endif
        setColor(g, bgBolor);
        if (startY + height > Constant.UI_START_Y + Constant.SCREEN_HEIGHT) {
            startY = Constant.UI_START_Y + Constant.SCREEN_HEIGHT - height - 2;
        }
        if (startX + width > Constant.UI_START_X + Constant.DRAW_WIDTH) {
            startX = Constant.UI_START_X + Constant.DRAW_WIDTH - width - 2;
        }
        g.fillRect(startX, startY, width, height);
        int iStartX = startX + 5;
        for (int i = 0; i < sOpArray.length; i++) {
            switch (byAlign) {
                case 3:
                    iStartX = startX + width - 5 - Constant.FONT_SMALL.stringWidth(sOpArray[i]);
                    break;
                case 1:
                    iStartX = startX + ((width - Constant.FONT_SMALL.stringWidth(sOpArray[i])) >> 1);
                    break;
            }
            if (bySelectIndex == i) {
                setColor(g, selectedColor);
            } else {
                setColor(g, fontColor);
            }
            g.drawString(sOpArray[i], iStartX, startY + 5 + i * lineHeight, 0);
            
        }
    }
    
    public static int[][] getPopMenuTouch(String[] sOpArray, byte byAlign, int width, int lineHeight, int bgBolor, int fontColor, int selectedColor, byte bySelectIndex, int startX, int startY) {
    	int size = sOpArray.length;
//    	lineHeight = Constant.FONT_SMALL_HEIGHT + 1;
        lineHeight = lineHeight < Constant.FONT_SMALL_HEIGHT ? Constant.FONT_SMALL_HEIGHT : lineHeight;
        int height = lineHeight * size + 10;
//        width = Constant.FONT_SMALL.stringWidth("查看") + 2;
        //#if NOKIA_S60V5
         height = height < 41 ? 41 : height;
        //#else
//#        height = height < 31 ? 31 : height;
        //#endif
//        setColor(g, bgBolor);
        if (startY + height > Constant.UI_START_Y + Constant.SCREEN_HEIGHT) {
            startY = Constant.UI_START_Y + Constant.SCREEN_HEIGHT - height - 2;
        }
        if (startX + width > Constant.UI_START_X + Constant.DRAW_WIDTH) {
            startX = Constant.UI_START_X + Constant.DRAW_WIDTH - width - 2;
        }
        int[][] rect = new int[size][];
        for (int i = 0; i < size; i++) {
//            switch (byAlign) {
//                case 3:
//                    iStartX = startX + width - 5 - Constant.FONT_SMALL.stringWidth(sOpArray[i]);
//                    break;
//                case 1:
//                    iStartX = startX + ((width - Constant.FONT_SMALL.stringWidth(sOpArray[i])) >> 1);
//                    break;
//            }
//            if (bySelectIndex == i) {
//                setColor(g, selectedColor);
//            } else {
//                setColor(g, fontColor);
//            }
//            g.drawString(sOpArray[i], iStartX, startY + 5 + i * lineHeight, 0);
        	rect[i] = new int[]{
        			startX, startY + 5 + i * lineHeight,width,lineHeight
        	};
        }
        return rect;
    }

    /**
     * 更新操作菜单的情况
     * @param menuOpNum  菜单数量
     * @param oldSelectIndex 以前的选择索引
     * @param direction 按键方向 (0,向上,1，向下)
     * @return 返回当前选择的索引
     */
    public static byte updatePopMenu(byte menuOpNum, byte oldSelectIndex, byte direction) {
        menuOpNum = (byte) (menuOpNum - 1);
        if (direction == 0) {
            //向上
            return (byte) (oldSelectIndex == 0 ? 0 : oldSelectIndex - 1);
        } else if (direction == 1) {
            //向下
            return (byte) (oldSelectIndex == menuOpNum ? menuOpNum : oldSelectIndex + 1);
        }
        return oldSelectIndex;
    }

    /**
     * @param img 原始图片
     * @param alpha 透明度数(取值范围在0x00~0xff之间;值越小,透明度超高)
     * @return   返回透明化后的图片
     */
    public static Image makeTransparent(Image img, int alpha) {
        int length = img.getWidth() * img.getHeight();
        int[] imgData = new int[length];
        int width = img.getWidth();
        int height = img.getHeight();
        img.getRGB(imgData, 0, img.getWidth(), 0, 0, img.getWidth(), img.getHeight());
        img = null;
        for (int i = 0; i < imgData.length; i++) {
            imgData[i] &= 0x00FFFFFF;
            //#if MOBILEID =="MOTO"
//#             if (imgData[i] != 16515324)
//#             {
//#                 imgData[i] = imgData[i] | (alpha << 24);
//#             }
            //#elif NORMAL_240_400
//#             if(imgData[i] != 16253176){
//#                 imgData[i] = imgData[i] | (alpha << 24);
//#             }
            //#else
            if (imgData[i] != 0x00ff00ff) {
                imgData[i] = imgData[i] | (alpha << 24);
            }
            //#endif
        }
        return Image.createRGBImage(imgData, width, height, true);
    }

    /**
     * 生成一张纯色图片的半透图
     * @param w 宽度
     * @param h 高度
     * @param alpha 办透值(0-255/0x00~0xff)
     * @param color  颜色
     * @return  透明处理过的图片
     */
    public static Image makeTransparent(int w, int h, int alpha, int color) {
        int length = w * h;
        int[] imageData = new int[length];
        for (int i = 0; i < length; i++) {
            imageData[i] = (alpha << 24) + color;
        }
        return Image.createRGBImage(imageData, w, h, true);
    }

    /**小图片拼接为大图片
     * @param g
     * @param direction  拼接方向:1:横向;2:纵向
     * @param startX  图片绘制开始位置
     * @param startY
     * @param borderLength   拼接的总长度
     * @param srcImg      拼接的小图片
     * @param imgStartX   
     * @param imgStartY
     * @param imgWidth    小图片宽
     * @param imgHeight  小图片高
     * @param transform  旋转方式
     */
    public static void drawTilePic(Graphics g, byte direction, int startX, int startY, int borderLength, Image srcImg, int imgStartX, int imgStartY, int imgWidth, int imgHeight, int transform) {
        //初始开始的位置，用于判断是否超过了
        if (borderLength < 0) {
            return;
        }
        int iOriginalStartX = startX;
        int iOriginalStartY = startY;
        int tempBorderH; // 防止图片重叠
        int tempImgW, tempImgH;
        boolean bFlag;
        switch ((byte) transform) {
            case Constant.TRANS_NONE:
            case Constant.TRANS_ROT180:
            case Constant.TRANS_MIRROR:
            case Constant.TRANS_MIRROR_ROT180:
                tempImgW = imgWidth;
                tempImgH = imgHeight;
                bFlag = true;
                break;
            case Constant.TRANS_ROT90:
            case Constant.TRANS_ROT270:
            case Constant.TRANS_MIRROR_ROT90:
            case Constant.TRANS_MIRROR_ROT270:
                tempImgW = imgHeight;
                tempImgH = imgWidth;
                bFlag = false;
                break;
            default:
                tempImgW = imgWidth;
                tempImgH = imgHeight;
                bFlag = true;
                break;
        }
        int n;
        if (direction == 1) {
            n = (borderLength % tempImgW == 0) ? borderLength / tempImgW : borderLength / tempImgW + 1; //需要填充的图片的数量
        } else {
            n = (borderLength % tempImgH == 0) ? borderLength / tempImgH : borderLength / tempImgH + 1; //需要填充的图片的数量
        }
        //填充
        for (int i = 1; i <= n; i++) {
            if (direction == 1) {
                if (startX + tempImgW >= iOriginalStartX + borderLength) {
                    tempBorderH = iOriginalStartX + borderLength - startX;
                } else {
                    tempBorderH = tempImgW;
                }
                if (bFlag) {
                    if (srcImg != null) {
                        g.drawRegion(srcImg, imgStartX, imgStartY, tempBorderH, imgHeight, transform, startX, startY, 0);
                    }
                } else {
                    if (srcImg != null) {
                        g.drawRegion(srcImg, imgStartX, imgStartY, imgWidth, tempBorderH, transform, startX, startY, 0);
                    }
                }
                startX = startX + tempBorderH;
            } else {
                if (startY + tempImgH >= iOriginalStartY + borderLength) {
                    tempBorderH = iOriginalStartY + borderLength - startY;
                } else {
                    tempBorderH = tempImgH;
                }
                if (bFlag) {
                    if (srcImg != null) {
                        g.drawRegion(srcImg, imgStartX, imgStartY, imgWidth, tempBorderH, transform, startX, startY, 0);
                    }
                } else {
                    if (srcImg != null) {
                        g.drawRegion(srcImg, imgStartX, imgStartY, tempBorderH, imgHeight, transform, startX, startY, 0);
                    }
                }
                startY = startY + tempBorderH;
            }
        }
    }

    /**
     * 获得插入的特殊字符表示的颜色
     * @param letter
     * @return
     */
    public static int getColor(char letter) {
        switch (Character.toLowerCase(letter)) {
            case 'a':
                return 0xFF9900;
            case 'b':
                return 0x990000;
            case 'c':
                return 0x33FF66;
            case 'd':
                return 0x3399CC;
            case 'e':
                return 0x333333;
            case 'f':
                return 0xffffff;
            case 'g':
                return 0x00ff33;
            case 'h':
                return 0x33b1fa;
            case 'i':
                return 0xff00ff;
            case 'j':
                return 0x999999;
            case 'k':
                return 0xFF0000;
            case 'l':
                return 0x00ccff;
            case 'm':
                return 0xffff00;
            default:
                return 0xFFFFFF;
        }
    }

    /**
     * 根据颜色获得段落中代表该种颜色的字符
     * @param letter
     * @return
     */
    public static char getColorReplaceLetter(int color) {
        switch (color) {
            case 0xFF9900:
                return 'a';
            case 0x990000:
                return 'b';
            case 0x33FF66:
                return 'c';
            case 0x3399CC:
                return 'd';
            case 0x333333:
                return 'e';
            case 0xffffff:
                return 'f';
            case 0x00ff33:
                return 'g';
            case 0x33b1fa:
                return 'h';
            case 0xff00ff:
                return 'i';
            case 0x999999:
                return 'j';
            case 0xFF0000:
                return 'k';
            case 0x00ccff:
                return 'l';
            case 0xffff00:
                return 'm';
            default:
                return 'z';
        }
    }

    /**
     * 绘制有透明度的弹出层,可以产生(小-> 中->大->中的动画效果)
     * @param g
     * @param state (1,小，2，中，3，大，4，中（最终的效果状态）)
     * @param startX  开始位置
     * @param startY
     * @param w   宽度
     * @param h 高度
     * @param framePic  边框图片
     * @param bgPic  背景填充图片
     * @param fillDirection  填充方向(1,横向，2，纵向)
     * @param buttonLeft  左边的button图片
     * @param imgLeftStartX  左边button文字的在图片上的位置
     * @param imgLeftStartY
     * @param buttonLeftW  右边button的宽度
     * @param buttonLeftH  右边button的高度
     * @param buttonRight   右边的button图片
     * @param imgRightStartX  右边button文字的在图片上的位置
     * @param imgRightStartY
     * @param buttonRightW  右边button的宽度
     * @param buttonRightH  右边button的高度
     * @param sTitle     标题(可以为null)
     * @param sContent   内容(可以为null)
     */
    public static void drawPopUp(Graphics g, byte state, int startX, int startY, int w, int h, Image framePic, Image bgPic, byte fillDirection, Image buttonLeft, int imgLeftStartX, int imgLeftStartY, int buttonLeftW, int buttonLeftH, Image buttonRight, int imgRightStartX, int imgRightStartY, int buttonRightW, int buttonRightH, String sTitle, String sContent) {
        //#if NOKIA_S40V3 || NORMAL_240_400 || MOT0 || K790
//#         state = 4;
        //#else
        if (state < 1 || state > 4) {
            return;
        }
        //#endif
        int xOld = g.getClipX();
        int yOld = g.getClipY();
        int wOld = g.getClipWidth();
        int hOld = g.getClipHeight();
        //根据提框的动画状态绘制提示框大小
        int iOldW = w;
        int iOldH = h;
        //提示框四个角的宽度和高度(宽度和高度相等)
        switch (state) {
            case 1:
                w = w - w / 2;
                h = h - h / 2;
                startX = startX + ((iOldW - w) >> 1);
                startY = startY + ((iOldH - h) >> 1);
                break;
            case 3:
                w = w + w / 10;
                h = h + h / 10;
                startX = startX - ((w - iOldW) >> 1);
                startY = startY - ((h - iOldH) >> 1);
                break;
            case 2:
            case 4:
            default:
                break;
        }

        //绘制标题背景图片
        //#if NOKIA_S60V5
         if (fillDirection == 1) {
             drawRoundRect(g, framePic, bgPic, fillDirection, 0, 0, bgPic.getWidth(), h - 26, w, h, startX, startY);
         } else {
             drawRoundRect(g, framePic, bgPic, fillDirection, 0, 0, w - 26, bgPic.getHeight(), w, h, startX, startY);
         }
         g.drawRegion(framePic, 42, 0, 10, 24, Constant.TRANS_NONE, startX + 3, startY + 3, 0); //头
         g.drawRegion(framePic, 42, 0, 10, 24, Constant.TRANS_ROT180, startX + w - 13, startY + 3, 0); //尾
         drawTilePic(g, (byte) 1, startX + 13, startY + 3, w - 26, framePic, 53, 0, 10, 24, Constant.TRANS_NONE);//中间
        //#else
//#        if (fillDirection == 1) {
//#            drawRoundRect(g, framePic, bgPic, fillDirection, 0, 0, bgPic.getWidth(), h - 14, w, h, startX, startY);
//#        } else {
//#            drawRoundRect(g, framePic, bgPic, fillDirection, 0, 0, w - 14, bgPic.getHeight(), w, h, startX, startY);
//#        }
//#        g.drawRegion(framePic, 27, 0, 5, 14, Constant.TRANS_NONE, startX + 3, startY + 3, 0); //头
//#        g.drawRegion(framePic, 27, 0, 5, 14, Constant.TRANS_ROT180, startX + w - 3 - 5, startY + 3, 0); //尾
//#        drawTilePic(g, (byte) 1, startX + 3 + 5, startY + 3, w - 6 - (5 << 1), framePic, 31, 0, 1, 14, Constant.TRANS_NONE);
        //#endif
        //绘制标题
        if (state == 4) {
            //绘制确定和取消按钮
//            if (buttonLeft != null) {
//                //#if NOKIA_S60V5
//                 g.drawRegion(buttonLeft, imgLeftStartX, imgLeftStartY, buttonLeftW, buttonLeftH, 0, startX + 6, startY + 3 + ((24 - buttonLeftH) >> 1), 0);
//                //#else
////#                g.drawRegion(buttonLeft, imgLeftStartX, imgLeftStartY, buttonLeftW, buttonLeftH, 0, startX + 6, startY + 3 + ((14 - buttonLeftH) >> 1), 0);
//                //#endif
//            }
//            if (buttonRight != null) {
//                //#if NOKIA_S60V5
//                 g.drawRegion(buttonRight, imgRightStartX, imgRightStartY, buttonRightW, buttonRightH, 0, startX + w - buttonRightW - 6, startY + 3 + ((24 - buttonRightH) >> 1), 0);
//                //#else
////#                g.drawRegion(buttonRight, imgRightStartX, imgRightStartY, buttonRightW, buttonRightH, 0, startX + w - buttonRightW - 6, startY + 3 + ((14 - buttonRightH) >> 1), 0);
//                //#endif
//
//            }
            if (sTitle != null && sTitle.length() > 1) {
                //快速注册
                if (GameBean.I_SYSTEM_MESSAGE_TYPE == 1) {
                    setColor(g, 0xa40001);
                } else {
                    setColor(g, 0xFFFFFF);
                }
                //#if NOKIA_S60V5
                 g.drawString(sTitle, startX + ((w - Constant.FONT_SMALL.stringWidth(sTitle)) >> 1), startY + 3 + ((24 - Constant.FONT_SMALL_HEIGHT) >> 1), g.LEFT | g.TOP);
                //#else
//#                g.drawString(sTitle, startX + ((w - Constant.FONT_SMALL.stringWidth(sTitle)) >> 1), startY + 6, g.LEFT | g.TOP);
                //#endif
            }
            if (sContent != null && sContent.length() > 1) {
                int height = getParagraphHeight(sContent, w - 20, Constant.FONT_SMALL_HEIGHT + 1);
                if (height > Constant.FONT_SMALL_HEIGHT) {
                    drawParagraph(g, startX + 10, startY + 20 + ((h - 30 - height) >> 1), w - 20, sContent, 0xFFFFFF, Constant.FONT_SMALL_HEIGHT + 1, 0x000000);
                } else {
                    drawParagraph(g, startX + 10 + ((w - 20 - Constant.FONT_SMALL.stringWidth(sContent)) >> 1), startY + 20 + ((h - 30 - height) >> 1), w - 20, sContent, 0xFFFFFF, Constant.FONT_SMALL_HEIGHT + 1, 0x000000);
                }
            }
        }
        g.setClip(xOld, yOld, wOld, hOld);
    }

    /**
     * 绘制没有透明度的弹出层,可以产生(小-> 中->大->中的动画效果)
     * @param g
     * @param state (1,小，2，中，3，大，4，中（最终的效果状态）)
     * @param startX  开始位置
     * @param startY
     * @param w   宽度
     * @param h 高度
     * @param framePic  边框图片
     * @param bgColor  北京颜色
     * @param buttonLeft  左边的button图片
     * @param imgLeftStartX  左边button文字的在图片上的位置
     * @param imgLeftStartY
     * @param buttonLeftW  右边button的宽度
     * @param buttonLeftH  右边button的高度
     * @param buttonRight   右边的button图片
     * @param imgRightStartX  右边button文字的在图片上的位置
     * @param imgRightStartY
     * @param buttonRightW  右边button的宽度
     * @param buttonRightH  右边button的高度
     * @param sTitle     标题(可以为null)
     * @param sContent   内容(可以为null)
     */
    public static void drawPopUp(Graphics g, byte state, int startX, int startY, int w, int h, Image framePic, int bgColor, Image buttonLeft, int imgLeftStartX, int imgLeftStartY, int buttonLeftW, int buttonLeftH, Image buttonRight, int imgRightStartX, int imgRightStartY, int buttonRightW, int buttonRightH, String sTitle, String sContent) {
        int xOld = g.getClipX();
        int yOld = g.getClipY();
        int wOld = g.getClipWidth();
        int hOld = g.getClipHeight();
        //根据提框的动画状态绘制提示框大小
        int iOldW = w;
        int iOldH = h;
        //提示框四个角的宽度和高度(宽度和高度相等)
        switch (state) {
            case 1:
                w = w - w / 2;
                h = h - h / 2;
                startX = startX + ((iOldW - w) >> 1);
                startY = startY + ((iOldH - h) >> 1);
                break;
            case 3:
                w = w + w / 10;
                h = h + h / 10;
                startX = startX - ((w - iOldW) >> 1);
                startY = startY - ((h - iOldH) >> 1);
                break;
            case 2:
            case 4:
            default:
                break;
        }

        //绘制最外层的提示框
        drawRoundRect(g, framePic, bgColor, w, h, startX, startY); //绘制标题背景图片
        //#if NOKIA_S60V5
         g.drawRegion(framePic, 42, 0, 10, 24, Constant.TRANS_NONE, startX + 3, startY + 3, 0); //头
         g.drawRegion(framePic, 42, 0, 10, 24, Constant.TRANS_ROT180, startX + w - 13, startY + 3, 0); //尾
         drawTilePic(g, (byte) 1, startX + 13, startY + 3, w - 26, framePic, 53, 0, 10, 24, Constant.TRANS_NONE);
        //#else
//#        g.drawRegion(framePic, 27, 0, 5, 14, Constant.TRANS_NONE, startX + 3, startY + 3, 0); //头
//#        g.drawRegion(framePic, 27, 0, 5, 14, Constant.TRANS_ROT180, startX + w - 3 - 5, startY + 3, 0); //尾
//#        drawTilePic(g, (byte) 1, startX + 3 + 5, startY + 3, w - 6 - (5 << 1), framePic, 31, 0, 1, 14, Constant.TRANS_NONE);
        //#endif
        //绘制标题
        if (state == 4) {
            //绘制确定和取消按钮
//            if (buttonLeft != null) {
//                //#if NOKIA_S60V5
//                 g.drawRegion(buttonLeft, imgLeftStartX, imgLeftStartY, buttonLeftW, buttonLeftH, 0, startX + 6, startY + 3 + ((24 - buttonLeftH) >> 1), 0);
//                //#else
////#                g.drawRegion(buttonLeft, imgLeftStartX, imgLeftStartY, buttonLeftW, buttonLeftH, 0, startX + 6, startY + 3 + ((14 - buttonLeftH) >> 1), 0);
//                //#endif
//            }
//            if (buttonRight != null) {
//                //#if NOKIA_S60V5
//                 g.drawRegion(buttonRight, imgRightStartX, imgRightStartY, buttonRightW, buttonRightH, 0, startX + w - buttonRightW - 6, startY + 3 + ((24 - buttonRightH) >> 1), 0);
//                //#else
////#                g.drawRegion(buttonRight, imgRightStartX, imgRightStartY, buttonRightW, buttonRightH, 0, startX + w - buttonRightW - 6, startY + 3 + ((14 - buttonRightH) >> 1), 0);
//                //#endif
//
//            }
            if (sTitle != null && sTitle.length() > 1) {
                setColor(g, 0x00FFFFFF);
                //#if NOKIA_S60V5
                 g.drawString(sTitle, startX + ((w - Constant.FONT_SMALL.stringWidth(sTitle)) >> 1), startY + 3 + ((24 - Constant.FONT_SMALL_HEIGHT) >> 1), g.LEFT | g.TOP);
                //#else
//#                g.drawString(sTitle, startX + ((w - Constant.FONT_SMALL.stringWidth(sTitle)) >> 1), startY + 6 + ((14 - Constant.FONT_SMALL_HEIGHT) >> 1), g.LEFT | g.TOP);
                //#endif
            }
            if (sContent != null && sContent.length() > 1) {
                int height = getParagraphHeight(sContent, w - 20, Constant.FONT_SMALL_HEIGHT);
                drawParagraph(g, startX + 10, startY + 20 + ((h - 30 - height) >> 1), w - 20, sContent, 0xFFFFFF, Constant.FONT_SMALL_HEIGHT + 1, 0x000000);
            }
        }
        g.setClip(xOld, yOld, wOld, hOld);
    }

    /**
     * 绘制一段文字，自动的换行，根据规制变色，特殊字符换行("#"为换行符，"<"为颜色变更符号，">"为颜色变更结束符号)
     * @param g
     * @param startX  开始位置
     * @param startY  
     * @param rowWidth 绘制的一行的宽度
     * @param text   文本的内容
     * @param fontColor  文本的字体颜色
     * @param rowHeight  行高
     * @param shadowColor 阴影的颜色（-1 为没有有阴影）
     */
    public static void drawParagraph(Graphics g, int startX, int startY, int rowWidth, String text, int fontColor, int rowHeight, int shadowColor) {
        if (text == null || "".equals(text)) {
            return;
        }
        int oldColor = g.getColor();
        setColor(g, fontColor);
        int length = text.length();
        char tempChar;
        int tempLength = 0;
        int iStartX = startX;
        int iStartY = startY;
        int color = fontColor;
        if (rowHeight < Constant.FONT_SMALL.getHeight()) {
            rowHeight = Constant.FONT_SMALL.getHeight();
        }
        for (int i = 0; i < length; i++) {
            tempChar = text.charAt(i);
            if (tempChar == '<') {
                if (i == length - 1) {
                    break;
                }
                tempChar = text.charAt(i + 1);
                color = getColor(tempChar);
                if (color != -1) {
                    setColor(g, color);
                    i += 1;
                }
            } else if (tempChar == '>') {
                color = fontColor;
                setColor(g, fontColor);
            } //            else if (tempChar == '#') {
            //                tempLength = 0;
            //                iStartX = startX;
            //                iStartY = iStartY + rowHeight;
            //            }
            else if (tempChar == '|') {
                tempLength = 0;
                iStartX = startX;
                iStartY = iStartY + rowHeight;
            } else {
                if (tempLength + Constant.FONT_SMALL.charWidth(tempChar) > rowWidth) {
                    iStartY = iStartY + rowHeight;
                    iStartX = startX;
                    tempLength = 0;
                }
                if (shadowColor >= 0) {
                    drawShadowWord(g, (byte) 1, tempChar, iStartX, iStartY, color, shadowColor);
                } else {
                    g.drawChar(tempChar, iStartX, iStartY, 0);
                }
                tempLength = tempLength + Constant.FONT_SMALL.charWidth(tempChar);
                iStartX = iStartX + Constant.FONT_SMALL.charWidth(tempChar);
            }
        }
        if (oldColor != fontColor) {
            setColor(g, oldColor);
        }
    }

    /**
     * 绘制一段文字，自动的换行，根据规制变色，特殊字符换行("|"为换行符，"<"为颜色变更符号，">"为颜色变更结束符号)
     * 并限制高度
     * @param g
     * @param startX  开始位置
     * @param startY  
     * @param rowWidth 绘制的一行的宽度
     * @param text   文本的内容
     * @param fontColor  文本的字体颜色
     * @param rowHeight  行高
     * @param shadowColor 阴影的颜色（-1 为没有有阴影）
     * @param limitStartY  绘制可见开始的位置
     * @param  iLimtHeight  高度
     */
    public static void drawParagraph(Graphics g, int startX, int startY, int rowWidth, String text, int fontColor, int rowHeight, int shadowColor, int limitStartY, int iLimtHeight) {
        int xOld = g.getClipX();
        int yOld = g.getClipY();
        int wOld = g.getClipWidth();
        int hOld = g.getClipHeight();
        int oldColor = g.getColor();
        g.setClip(startX, limitStartY, rowWidth, iLimtHeight);
        drawParagraph(g, startX, startY, rowWidth, text, fontColor, rowHeight, shadowColor);
        g.setClip(xOld, yOld, wOld, hOld);
    }

    /**
     * 获取一段要绘制的文本的高度（指定的宽度和行高）
     * @param text 文本
     * @param rowWidth 绘制的宽度
     * @param rowWidth 文本的行高
     * @return
     */
    public static int getParagraphHeight(String text, int rowWidth, int rowHeight) {
        if (text == null) {
            return 0;
        }
        if (rowHeight < Constant.FONT_SMALL_HEIGHT) {
            rowHeight = Constant.FONT_SMALL_HEIGHT;
        }
        int length = text.length();
        char tempChar;
        int tempLength = 0;
        int height = 0;
        for (int i = 0; i < length; i++) {
            tempChar = text.charAt(i);
            if (tempChar == '<') {
                if (i + 1 == length) {
                    break;
                }
                tempChar = text.charAt(i + 1);
                if (getColor(tempChar) > -1) {
                    i += 1;
                }
                continue;
            } else if (tempChar == '>') {
                continue;
            } else if (tempChar == '|') {
                tempLength = 0;
                height = height + rowHeight;
            } else {
                if (tempLength + Constant.FONT_SMALL.charWidth(tempChar) > rowWidth) {
                    tempLength = 0;
                    height = height + rowHeight;
                }
                tempLength = tempLength + Constant.FONT_SMALL.charWidth(tempChar);
            }
        }
        height = height + rowHeight;
        return height;
    }

    /**
     * 绘制一段带有阴影的文字
     * @param g
     * @param byType 绘制的方式(1,绘制5遍，2.绘制3遍)
     * @param str  要绘制的字符串
     * @param iOriStartX 原始位置
     * @param OriStartY
     * @param iFontColor 字体颜色
     * @param iShadowColor  阴影颜色
     */
    public static void drawShadowString(Graphics g, byte byType, String str, int iOriStartX, int OriStartY, int iFontColor, int iShadowColor) {
        if (str == null) {
            return;
        }
        //#if NOKIA_S60V5 || NOKIA_S40V3 || NOKIAN73 || NORMAL_240_400 || MOT0 || K790
        //#else
//#        setColor(g, iShadowColor);
//#        g.drawString(str, iOriStartX - 1, OriStartY, 0);
//#        if (byType == 1) {
//#            g.drawString(str, iOriStartX + 1, OriStartY, 0);
//#            g.drawString(str, iOriStartX, OriStartY - 1, 0);
//#        }
//#        g.drawString(str, iOriStartX, OriStartY + 1, 0);
        //#endif
        setColor(g, iFontColor);
        g.drawString(str, iOriStartX, OriStartY, 0);
    }

    /**
     * 绘制一段带有阴影的文字，可以设置对齐方式
     * @param g
     * @param byType 绘制的方式(1,绘制5遍，2.绘制3遍)
     * @param str  要绘制的字符串
     * @param iOriStartX 原始位置
     * @param OriStartY
     * @param iFontColor 字体颜色
     * @param iShadowColor  阴影颜色
     * @param anchor
     */
    public static void drawShadowString(Graphics g, byte byType, String str, int iOriStartX, int OriStartY, int iFontColor, int iShadowColor, int anchor) {
        if (str == null) {
            return;
        }
        //#if NOKIA_S60V5 || NOKIA_S40V3 || NOKIAN73 || NORMAL_240_400 || MOT0 || K790
        //#else
//#        setColor(g, iShadowColor);
//#        g.drawString(str, iOriStartX - 1, OriStartY, anchor);
//#        if (byType == 1) {
//#            g.drawString(str, iOriStartX + 1, OriStartY, anchor);
//#            g.drawString(str, iOriStartX, OriStartY - 1, anchor);
//#        }
//#        g.drawString(str, iOriStartX, OriStartY + 1, anchor);
        //#endif
        setColor(g, iFontColor);
        g.drawString(str, iOriStartX, OriStartY, anchor);
        
        
    }

    /**
     * 绘制单个的描边字
     * @param g
     * @param word
     * @param byType 绘制的方式(1,绘制5遍，2.绘制3遍)
     * @param iOriStartX 原始位置
     * @param OriStartY
     * @param iFontColor  字体颜色
     * @param iShadowColor 阴影颜色
     */
    public static void drawShadowWord(Graphics g, byte byType, char word, int iOriStartX, int OriStartY, int iFontColor, int iShadowColor) {
        //#if NOKIA_S60V5 || NOKIA_S40V3 || NORMAL_240_400 || MOT0 || K790
         g.setColor(iFontColor);
         g.drawChar(word, iOriStartX, OriStartY, 0);
        //#else
//#        setColor(g, iShadowColor);
//#        g.drawChar(word, iOriStartX - 1, OriStartY, 0);
//#        if (byType == 1) {
//#            g.drawChar(word, iOriStartX + 1, OriStartY, 0);
//#            g.drawChar(word, iOriStartX, OriStartY - 1, 0);
//#        }
//#        g.drawChar(word, iOriStartX, OriStartY + 1, 0);
//#        g.setColor(iFontColor);
//#        g.drawChar(word, iOriStartX, OriStartY, 0);
        //#endif

        
    }
    public static int rollIndex; //滚动开始的垂直索引
    public static long lastUpdateTime; //上次更新位置的时间

    /**
     * 绘制上下滚动的文字段落
     * @param g
     * @param text  文字内容
     * @param textHeight  指定宽度的文本的总的高度
     * @param width  显示段落的宽带
     * @param height  显示段落的高度
     * @param rowHeight 文字的行高
     * @param startX  绘制开始的位置
     * @param startY
     * @param color  文字的颜色
     * @param shadowColor  阴影颜色(-1为没有阴影)
     */
    public static void drawHCycleRollingParagraph(Graphics g, String text, int textHeight, int width, int height, int rowHeight, int startX, int startY, int color, int shadowColor) {
        if (textHeight <= height) {
            drawParagraph(g, startX, startY, width, text, color, rowHeight, shadowColor);
            return;
        }
        if (rollIndex == 0) {
            if (System.currentTimeMillis() - lastUpdateTime > 3000) {
                rollIndex++;
                lastUpdateTime = System.currentTimeMillis();
            }
        } else {
            if (System.currentTimeMillis() - lastUpdateTime > Constant.CYCLE_ROLLING_UPDATE_INTERVAL) {
                if (rollIndex * Constant.CYCLE_ROLLING_SPEED > textHeight) {
                    rollIndex = 0;
                } else {
                    rollIndex++;
                }
                lastUpdateTime = System.currentTimeMillis();
            }
        }
        drawParagraph(g, startX, startY - rollIndex * Constant.CYCLE_ROLLING_SPEED, width, text, color, rowHeight, shadowColor, startY, height);
    }

    /**
     * 绘制通用的UI背景
     * @param g 
     * @param startX  开始坐标
     * @param startY
     * @param framBg  背景图片
     * @param arrow   箭头图片
     * @param mask    选择遮罩图片
     * @param buttonLeft  左按钮图片
     * @param imgLeftStartX  图片文字开始位置
     * @param imgLeftStartY
     * @param buttonLeftW   图片文字宽度
     * @param buttonLeftH   图片文字高度
     * @param buttonRight  右按钮图片
     * @param imgRightStartX  图片文字开始位置
     * @param imgRightStartY
     * @param buttonRightW  图片文字宽度
     * @param buttonRightH  图片文字高度
     * @param sTitle     标题
     * @param titleColor  标题颜色
     */
    public static void drawFrame(Graphics g, int startX, int startY, Image framBg, Image arrow, Image mask, Image buttonLeft, int imgLeftStartX, int imgLeftStartY, int buttonLeftW, int buttonLeftH, Image buttonRight, int imgRightStartX, int imgRightStartY, int buttonRightW, int buttonRightH, String sTitle, int titleColor) {
        //#if NOKIA_S40V3 || NORMAL_240_400 || MOT0 || K790
//#         if (framBg == null) {
//#             g.setColor(0x000000);
//#             g.fillRect(startX, startY, Constant.DRAW_WIDTH, Constant.DRAW_HEIGHT);
//#         } else {
//#             g.drawImage(framBg, startX, startY, 0);
//#         }
        //#else
        if (framBg != null) {
            g.drawImage(framBg, startX, startY, 0);
        }
        //#endif
        //标题背景
        setColor(g, 0x393939);
        g.fillRect(startX, startY, Constant.DRAW_WIDTH, 21);
        //标题
        if (sTitle != null && sTitle.length() > 0) {
            drawShadowString(g, (byte) 1, sTitle, startX + ((Constant.DRAW_WIDTH - Constant.FONT_SMALL.stringWidth(sTitle)) >> 1), startY + 1, 0xFFFFFF, 0x000000);
        }
        
        if (mask != null) {
            drawSelectMask(g, (byte) 2, mask, startX, startY + Constant.DRAW_HEIGHT - 25, Constant.DRAW_WIDTH);
        }
        if (buttonLeft != null) {
            g.drawRegion(buttonLeft, imgLeftStartX, imgLeftStartY, buttonLeftW, buttonLeftH, Constant.TRANS_NONE, startX + 8, startY + Constant.DRAW_HEIGHT - 25 + (25 - buttonLeftH >> 1), 0);
            if (arrow != null) {
                drawArrow(g, arrow, (byte) 2, startX + 15 + buttonLeftW, startY + Constant.DRAW_HEIGHT - 25 + (25 - 7 >> 1));
            }
        }
        if (buttonRight != null) {
            g.drawRegion(buttonRight, imgRightStartX, imgRightStartY, buttonRightW, buttonRightH, Constant.TRANS_NONE, startX + Constant.DRAW_WIDTH - 8 - buttonRightW, startY + Constant.DRAW_HEIGHT - 25 + (25 - buttonRightH >> 1), 0);
            if (arrow != null) {
                drawArrow(g, arrow, (byte) 1, startX + Constant.SCREEN_WIDTH - 20 - buttonRightW, startY + Constant.DRAW_HEIGHT - 25 + (25 - 7 >> 1));
            }
        }
    }
    
    public static void drawFrame(Graphics g, Image framBg, Image mask, String sButtonLeft, String sButtonRight, String sTitle) {
        //#if NOKIA_S40V3 || NORMAL_240_400 || MOT0 || K790
//#         if (framBg == null) {
//#             g.setColor(0x000000);
//#             g.fillRect(Constant.UI_START_X, Constant.UI_START_Y, Constant.DRAW_WIDTH, Constant.DRAW_HEIGHT);
//#         } else {
//#             g.drawImage(framBg, Constant.UI_START_X, Constant.UI_START_Y, 0);
//#         }
        //#else
        if (framBg != null) {
            g.drawImage(framBg, Constant.UI_START_X, Constant.UI_START_Y, 0);
        }
        //#endif
        //标题背景
        setColor(g, 0x393939);
        g.fillRect(Constant.UI_START_X, Constant.UI_START_Y, Constant.DRAW_WIDTH, 21);
        //标题
        if (sTitle != null && sTitle.length() > 0) {
            drawShadowString(g, (byte) 1, sTitle, Constant.UI_START_X + ((Constant.DRAW_WIDTH - Constant.FONT_SMALL.stringWidth(sTitle)) >> 1), Constant.UI_START_Y + 1, 0xFFFFFF, 0x000000);
        }
        
        if (mask != null) {
            drawSelectMask(g, (byte) 2, mask, Constant.UI_START_X, Constant.UI_START_Y + Constant.DRAW_HEIGHT - 25, Constant.DRAW_WIDTH);
        }
        if (sButtonLeft != null) {
            Tools.drawShadowString(g, (byte) 1, sButtonLeft, Constant.UI_START_X + 8, Constant.UI_START_Y + Constant.DRAW_HEIGHT - 3 - Constant.FONT_SMALL_HEIGHT, Constant.SELECTED_COLOR, 0x000000);
        }
        if (sButtonRight != null) {
            Tools.drawShadowString(g, (byte) 1, sButtonRight, Constant.UI_START_X + Constant.DRAW_WIDTH - 8, Constant.UI_START_Y + Constant.DRAW_HEIGHT - 3 - Constant.FONT_SMALL_HEIGHT, Constant.SELECTED_COLOR, 0x000000, g.RIGHT | g.TOP);
        }
    }

    //#if NOKIA_S60V5
     /**
      * 绘制60v5 背景界面
      * @param g
      * @param startX
      * @param startY
      * @param framBg
      * @param mask
      * @param button
      * @param sTitle
      */
     public static void drawS60V5Frame(Graphics g, Image framBg, Image direction, Image sureButton, Image mask, Image word, String sTitle) {
         if (framBg != null) {
             g.drawImage(framBg, Constant.UI_START_X, Constant.UI_START_Y, Graphics.TOP | Graphics.LEFT);
         }
         //标题
         if (sTitle != null && sTitle.length() > 0) {
             drawShadowString(g, (byte) 1, sTitle, Constant.UI_START_X + ((Constant.DRAW_WIDTH - Constant.FONT_SMALL.stringWidth(sTitle)) >> 1), Constant.UI_START_Y + ((41 - Constant.FONT_SMALL_HEIGHT) >> 1), 0xFFFFFF, 0x000000);
         }
         //绘制方向按钮
         if (direction != null) {
             drawS60V5Direction(g, direction, Constant.UI_START_X + 10, Constant.UI_START_Y + 410);
         }
         //绘制确定按钮
         if (sureButton != null) {
             g.drawRegion(sureButton, 0, 0, 92, 92, Constant.TRANS_NONE, Constant.UI_START_X + 240, Constant.UI_START_Y + 445, 0);//确定
             if (MainCanvas.KEY == Constant.FIRE) {
                 g.drawRegion(sureButton, 90, 0, 92, 92, Constant.TRANS_NONE, Constant.UI_START_X + 240, Constant.UI_START_Y + 445, 0);//确定
             }
         }
 
         if (mask != null) {
             //选择线
             drawTilePic(g, (byte) 1, Constant.UI_START_X, Constant.UI_START_Y + Constant.DRAW_HEIGHT - 57, Constant.DRAW_WIDTH, mask, 0, 0, 57, 57, Constant.TRANS_ROT180);
             drawTilePic(g, (byte) 1, Constant.UI_START_X, Constant.UI_START_Y + Constant.DRAW_HEIGHT - 57, Constant.DRAW_WIDTH, mask, 0, 0, 57, 24, Constant.TRANS_NONE);
         }
         if (word != null) {
             //绘制文字
 //            g.drawRegion(word, 52, 2, 43, 22, Constant.TRANS_NONE, Constant.UI_START_X + 8, Constant.UI_START_Y + Constant.DRAW_HEIGHT - 38, Graphics.TOP | Graphics.LEFT);
             g.drawRegion(word, 100, 2, 45, 20, Constant.TRANS_NONE, Constant.UI_START_X + 8, Constant.UI_START_Y + Constant.DRAW_HEIGHT - 38, Graphics.TOP | Graphics.LEFT);
             g.drawRegion(word, 1, 2, 47, 21, Constant.TRANS_NONE, Constant.UI_START_X + 304, Constant.UI_START_Y + Constant.DRAW_HEIGHT - 38, Graphics.TOP | Graphics.LEFT);
 //            g.drawRegion(word, 1, 2, 47, 21, Constant.TRANS_NONE, Constant.UI_START_X + 8, Constant.UI_START_Y + Constant.DRAW_HEIGHT - 38, Graphics.TOP | Graphics.LEFT);
 //            g.drawRegion(word, 52, 2, 43, 22, Constant.TRANS_NONE, Constant.UI_START_X + 304, Constant.UI_START_Y + Constant.DRAW_HEIGHT - 38, Graphics.TOP | Graphics.LEFT);
         }
     }
 
     /**
      * 绘制60v5 背景界面
      * @param g
      * @param startX
      * @param startY
      * @param framBg
      * @param mask
      * @param direction
      * @param sureButton
      * @param buttonLeft  左按钮图片
      * @param imgLeftStartX  图片文字开始位置
      * @param imgLeftStartY
      * @param buttonLeftW   图片文字宽度
      * @param buttonLeftH   图片文字高度
      * @param buttonRight  右按钮图片
      * @param imgRightStartX  图片文字开始位置
      * @param imgRightStartY
      * @param buttonRightW  图片文字宽度
      * @param buttonRightH  图片文字高度
      * @param sTitle
      */
     public static void drawS60V5Frame(Graphics g, Image framBg, Image direction, Image sureButton, Image mask, Image buttonLeft,
             int imgLeftStartX, int imgLeftStartY, int buttonLeftW, int buttonLeftH, Image buttonRight, int imgRightStartX,
             int imgRightStartY, int buttonRightW, int buttonRightH, String sTitle) {
         if (framBg != null) {
             g.drawImage(framBg, Constant.UI_START_X, Constant.UI_START_Y, Graphics.TOP | Graphics.LEFT);
         }
         //标题
         if (sTitle != null && sTitle.length() > 0) {
             drawShadowString(g, (byte) 1, sTitle, Constant.UI_START_X + ((Constant.DRAW_WIDTH - Constant.FONT_SMALL.stringWidth(sTitle)) >> 1), Constant.UI_START_Y + ((41 - Constant.FONT_SMALL_HEIGHT) >> 1), 0xFFFFFF, 0x000000);
         }
         //绘制方向按钮
         if (direction != null) {
             drawS60V5Direction(g, direction, Constant.UI_START_X + 10, Constant.UI_START_Y + 410);
         }
         //绘制确定按钮
         if (sureButton != null) {
             g.drawRegion(sureButton, 0, 0, 92, 92, Constant.TRANS_NONE, Constant.UI_START_X + 240, Constant.UI_START_Y + 445, 0);//确定
             if (MainCanvas.KEY == Constant.FIRE) {
                 g.drawRegion(sureButton, 90, 0, 92, 92, Constant.TRANS_NONE, Constant.UI_START_X + 240, Constant.UI_START_Y + 445, 0);//确定
             }
         }
 
         if (mask != null) {
             //选择线
             drawTilePic(g, (byte) 1, Constant.UI_START_X, Constant.UI_START_Y + Constant.DRAW_HEIGHT - 57, Constant.DRAW_WIDTH, mask, 0, 0, 57, 57, Constant.TRANS_ROT180);
             drawTilePic(g, (byte) 1, Constant.UI_START_X, Constant.UI_START_Y + Constant.DRAW_HEIGHT - 57, Constant.DRAW_WIDTH, mask, 0, 0, 57, 24, Constant.TRANS_NONE);
         }
         if (buttonLeft != null) {
             g.drawRegion(buttonLeft, imgLeftStartX, imgLeftStartY, buttonLeftW, buttonLeftH, Constant.TRANS_NONE,
                     Constant.UI_START_X + 8, Constant.UI_START_Y + Constant.DRAW_HEIGHT - 38, 0);
         }
         if (buttonRight != null) {
             g.drawRegion(buttonRight, imgRightStartX, imgRightStartY, buttonRightW, buttonRightH, Constant.TRANS_NONE,
                     Constant.UI_START_X + Constant.DRAW_WIDTH - 8 - buttonRightW, Constant.UI_START_Y + Constant.DRAW_HEIGHT - 38, 0);
         }
     }
 
     /*绘制方向键
      * @param x 左方向键的x坐标
      * @param y 上方向键的y坐标
      */
     public static void drawS60V5Direction(Graphics g, Image direction, int x, int y) {
         if (direction != null) {
             g.drawRegion(direction, 79, 7, 58, 80, Constant.TRANS_NONE, x + 50, y, 0);//上方向
             g.drawRegion(direction, 79, 7, 58, 80, Constant.TRANS_ROT180, x + 50, y + 80, 0);//下方向
             g.drawRegion(direction, 79, 7, 58, 80, Constant.TRANS_ROT270, x, y + 50, 0);//左方向
             g.drawRegion(direction, 79, 7, 58, 80, Constant.TRANS_ROT90, x + 80, y + 50, 0);//右方向
             if (MainCanvas.KEY == Constant.UP) {
                 g.drawRegion(direction, 7, 7, 58, 80, Constant.TRANS_NONE, x + 50, y, 0);//上方向
             } else if (MainCanvas.KEY == Constant.DOWN) {
                 g.drawRegion(direction, 7, 7, 58, 80, Constant.TRANS_ROT180, x + 50, y + 80, 0);//下方向
             } else if (MainCanvas.KEY == Constant.LEFT) {
                 g.drawRegion(direction, 7, 7, 58, 80, Constant.TRANS_ROT270, x, y + 50, 0);//左方向
             } else if (MainCanvas.KEY == Constant.RIGHT) {
                 g.drawRegion(direction, 7, 7, 58, 80, Constant.TRANS_ROT90, x + 80, y + 50, 0);//右方向
             }
         }
     }
 
     /*
      * 绘制底部
      */
     public static void drawBottom(Graphics g, Image word, Image direction, Image mask) {
         if (mask != null) {
             //选择线
             drawTilePic(g, (byte) 1, Constant.UI_START_X, Constant.UI_START_Y + Constant.DRAW_HEIGHT - 57,
                     Constant.DRAW_WIDTH, mask, 0, 0, 57, 57, Constant.TRANS_NONE);
         }
         if (word != null) {
             //绘制文字
             g.drawRegion(word, 48, 0, 48, 24, Constant.TRANS_NONE, Constant.UI_START_X + 8,
                     Constant.UI_START_Y + Constant.DRAW_HEIGHT - 38, Graphics.TOP | Graphics.LEFT);
             g.drawRegion(word, 0, 0, 48, 24, Constant.TRANS_NONE, Constant.UI_START_X + 304,
                     Constant.UI_START_Y + Constant.DRAW_HEIGHT - 38, Graphics.TOP | Graphics.LEFT);
         }
//         if (direction != null) {
//             g.drawRegion(direction, 49, 0, 49, 49, Constant.TRANS_NONE,
//                     Constant.UI_START_X + (Constant.DRAW_WIDTH - 49 * 4 >> 1),
//                     Constant.UI_START_Y + Constant.DRAW_HEIGHT - 57 + (57 - 49 >> 1), 0);//上方向
//             g.drawRegion(direction, 49, 0, 49, 49, Constant.TRANS_ROT180,
//                     Constant.UI_START_X + (Constant.DRAW_WIDTH - 49 * 4 >> 1) + 49,
//                     Constant.UI_START_Y + Constant.DRAW_HEIGHT - 57 + (57 - 49 >> 1), 0);//下方向
//             g.drawRegion(direction, 49, 0, 49, 49, Constant.TRANS_ROT270,
//                     Constant.UI_START_X + (Constant.DRAW_WIDTH - 49 * 4 >> 1) + 98,
//                     Constant.UI_START_Y + Constant.DRAW_HEIGHT - 57 + (57 - 49 >> 1), 0);//左方向
//             g.drawRegion(direction, 49, 0, 49, 49, Constant.TRANS_ROT90,
//                     Constant.UI_START_X + (Constant.DRAW_WIDTH - 49 * 4 >> 1) + 147,
//                     Constant.UI_START_Y + Constant.DRAW_HEIGHT - 57 + (57 - 49 >> 1), 0);//右方向
//             if (MainCanvas.KEY_BOTTOM == Constant.UP) {
//                 g.drawRegion(direction, 0, 0, 49, 49, Constant.TRANS_NONE,
//                         Constant.UI_START_X + (Constant.DRAW_WIDTH - 49 * 4 >> 1),
//                         Constant.UI_START_Y + Constant.DRAW_HEIGHT - 57 + (57 - 49 >> 1), 0);//上方向
//             } else if (MainCanvas.KEY_BOTTOM == Constant.DOWN) {
//                 g.drawRegion(direction, 0, 0, 49, 49, Constant.TRANS_ROT180,
//                         Constant.UI_START_X + (Constant.DRAW_WIDTH - 49 * 4 >> 1) + 49,
//                         Constant.UI_START_Y + Constant.DRAW_HEIGHT - 57 + (57 - 49 >> 1), 0);//下方向
//             } else if (MainCanvas.KEY_BOTTOM == Constant.LEFT) {
//                 g.drawRegion(direction, 0, 0, 49, 49, Constant.TRANS_ROT270,
//                         Constant.UI_START_X + (Constant.DRAW_WIDTH - 49 * 4 >> 1) + 98,
//                         Constant.UI_START_Y + Constant.DRAW_HEIGHT - 57 + (57 - 49 >> 1), 0);//左方向
//             } else if (MainCanvas.KEY_BOTTOM == Constant.RIGHT) {
//                 g.drawRegion(direction, 0, 0, 49, 49, Constant.TRANS_ROT90,
//                         Constant.UI_START_X + (Constant.DRAW_WIDTH - 49 * 4 >> 1) + 147,
//                         Constant.UI_START_Y + Constant.DRAW_HEIGHT - 57 + (57 - 49 >> 1), 0);//右方向
//             }
//         }
     }
    //#endif
    //#if NOKIA_E72
//#     /**
//#      * 绘制E72背景界面
//#      * @param g
//#      * @param startX
//#      * @param startY
//#      * @param framBg
//#      * @param mask
//#      * @param button
//#      * @param sTitle
//#      */
//#     public static void drawE72Frame(Graphics g, Image framBg, Image word, String sTitle) {
//#         g.drawImage(framBg, Constant.UI_START_X, Constant.UI_START_Y, 0);
//#         //标题背景
//#         setColor(g, 0x393939);
//#         g.fillRect(Constant.UI_START_X, Constant.UI_START_Y + MainLogic.getInstance().uiInterFace.iScreenOffsetH, Constant.DRAW_WIDTH, 21);
//#         //标题
//#         if (sTitle != null && sTitle.length() > 0) {
//#             drawShadowString(g, (byte) 1, sTitle, Constant.UI_START_X + ((Constant.DRAW_WIDTH - Constant.FONT_SMALL.stringWidth(sTitle)) >> 1), Constant.UI_START_Y + ((21 - Constant.FONT_SMALL_HEIGHT) >> 1) + MainLogic.getInstance().uiInterFace.iScreenOffsetH, 0xFFFFFF, 0x000000);
//#         }
//#         if (word != null) {
//#             g.drawRegion(word, 0, 0, 24, 12, Constant.TRANS_NONE, Constant.UI_START_X + 10, Constant.UI_START_Y + Constant.DRAW_HEIGHT - 16, 0);
//#             g.drawRegion(word, 49, 0, 23, 12, Constant.TRANS_NONE, Constant.UI_START_X + Constant.DRAW_WIDTH - 33, Constant.UI_START_Y + Constant.DRAW_HEIGHT - 16, 0);
//#         }
//#     }
//# 
//#     public static void drawE72Frame(Graphics g, Image framBg, String sLeftButton, String sRightButton, String sTitle) {
//#         g.drawImage(framBg, Constant.UI_START_X, Constant.UI_START_Y, 0);
//#         //标题背景
//#         setColor(g, 0x393939);
//#         g.fillRect(Constant.UI_START_X, Constant.UI_START_Y + MainLogic.getInstance().uiInterFace.iScreenOffsetH, Constant.DRAW_WIDTH, 21);
//#         //标题
//#         if (sTitle != null && sTitle.length() > 0) {
//#             drawShadowString(g, (byte) 1, sTitle, Constant.UI_START_X + ((Constant.DRAW_WIDTH - Constant.FONT_SMALL.stringWidth(sTitle)) >> 1), Constant.UI_START_Y + ((21 - Constant.FONT_SMALL_HEIGHT) >> 1) + MainLogic.getInstance().uiInterFace.iScreenOffsetH, 0xFFFFFF, 0x000000);
//#         }
//#         if (sLeftButton != null) {
//#             Tools.drawShadowString(g, (byte) 1, sLeftButton, Constant.UI_START_X + 8, Constant.UI_START_Y + Constant.DRAW_HEIGHT - 2 - Constant.FONT_SMALL_HEIGHT, Constant.SELECTED_COLOR, 0x000000);
//#         }
//#         if (sRightButton != null) {
//#             Tools.drawShadowString(g, (byte) 1, sRightButton, Constant.UI_START_X + Constant.DRAW_WIDTH - 8, Constant.UI_START_Y + Constant.DRAW_HEIGHT - 2 - Constant.FONT_SMALL_HEIGHT, Constant.SELECTED_COLOR, 0x000000, g.RIGHT | g.TOP);
//#         }
//#     }
    //#endif
    /**
     * 通过灰度图产生一张指定颜色半透明的图片
     * @param image 灰度图
     * @param rgb 目标颜色
     * @return
     */
    public static Image createPicFromGrayscale(Image image, int rgb) {
        int width = image.getWidth();
        int height = image.getHeight();
        int length = width * height;
        int[] imageData;
        imageData = new int[length];
        image.getRGB(imageData, 0, width, 0, 0, width, height);
        image = null;
        int temp;
        if (rgb == -1) {
            for (int i = 0; i < length; i++) {
                //获得透明度
                temp = imageData[i] & 0x000000FF;
                imageData[i] = (imageData[i] & 0x00ffffff) | (temp << 24);
            }
        } else {
            rgb = rgb & 0x00ffffff;
            for (int i = 0; i < length; i++) {
                //获得透明度
                temp = imageData[i] & 0x000000FF;
                imageData[i] = rgb | (temp << 24);
            }
        }
        return Image.createRGBImage(imageData, width, height, true);
    }

    /**
     * 绘制一个button文字
     * @param g  
     * @param word 要绘制的文字
     * @param bSelected 是否是选中
     * @param arrowImage  箭头图片
     * @param startX  始坐标
     * @param startY
     * @param fontColor  没有被选中的颜色
     * @param selectColor  选中后的颜色
     * @param shadowcolor   阴影颜色(-1为没有阴影)
     */
    public static void drawOpWord(Graphics g, String word, boolean bSelected, byte byArrowType, Image arrowImage, int startX, int startY, int fontColor, int selectColor, int shadowcolor) {
        if (bSelected) {
            if (shadowcolor > -1) {
                drawShadowString(g, (byte) 1, word, startX, startY, selectColor, shadowcolor);
            } else {
                setColor(g, selectColor);
                g.drawString(word, startX, startY, 0);
            }
            if (arrowImage != null) {
                if (byArrowType == 1) {
                    drawArrow(g, arrowImage, (byte) 1, startX - 10, startY + ((Constant.FONT_SMALL_HEIGHT - 7) >> 1));
                    drawArrow(g, arrowImage, (byte) 2, startX + 5 + Constant.FONT_SMALL.stringWidth(word), startY + ((Constant.FONT_SMALL_HEIGHT - 7) >> 1));
                } else {
                    drawBigArrow(g, arrowImage, (byte) 1, startX - 14, startY + ((Constant.FONT_SMALL_HEIGHT - 13) >> 1));
                    drawBigArrow(g, arrowImage, (byte) 2, startX + 5 + Constant.FONT_SMALL.stringWidth(word), startY + ((Constant.FONT_SMALL_HEIGHT - 13) >> 1));
                }
            }
        } else {
            if (shadowcolor > -1) {
                drawShadowString(g, (byte) 1, word, startX, startY, fontColor, shadowcolor);
            } else {
                setColor(g, fontColor);
                g.drawString(word, startX, startY, 0);
            }
        }
    }

    /**
     * 绘制金钱图片显示
     * @param g
     * @param lCopper  金钱数量(以铜币为单位)
     * @param wordPic   文字图片
     * @param goldPic  金币图标
     * @param numicPic  数字图片
     * @param startX  开始位置
     * @param startY
     */
    public static void drawMoney(Graphics g, long lCopper, Image wordPic, Image goldPic, Image numicPic, int startX, int startY) {
        long money = 0;
        byte byPre = 0;
        //绘制龙币
        g.drawRegion(wordPic, 46, 12, 25, 12, Constant.TRANS_NONE, startX, startY, 0);
        startX = startX + 26;
        if (lCopper >= 10000) {
            money = (long) (lCopper / 10000);
            lCopper = lCopper - (10000 * money);
            //金币图片
            g.drawRegion(goldPic, 0, 0, 12, 12, Constant.TRANS_NONE, startX, startY, 0);
            //绘制金币数字
            startX = startX + 13;
            startX = drawNumPic(g, numicPic, String.valueOf(money), (byte) 2, startX, startY + 1, (byte) 2);
            g.drawRegion(wordPic, 73, 24, 13, 12, Constant.TRANS_NONE, startX, startY, 0);
            startX = startX + 14;
            byPre = 1;
        }
        if (lCopper >= 100) {
            money = (long) (lCopper / 100);
            lCopper = (long) (lCopper - 100 * money);
            //银币图片
            g.drawRegion(goldPic, 12, 0, 12, 12, Constant.TRANS_NONE, startX, startY, 0);
            //绘制银币数字
            startX = startX + 13;
            startX = drawNumPic(g, numicPic, String.valueOf(money), (byte) 2, startX, startY + 1, (byte) 2);
            g.drawRegion(wordPic, 85, 24, 13, 12, Constant.TRANS_NONE, startX, startY, 0);
            startX = startX + 14;
            byPre = 1;
        }
        if (lCopper > 0 || (lCopper == 0 && byPre == 0)) {
            //铜币图片
            g.drawRegion(goldPic, 24, 0, 12, 12, Constant.TRANS_NONE, startX, startY, 0);
            //绘制银币数字
            startX = startX + 13;
            startX = drawNumPic(g, numicPic, String.valueOf(lCopper), (byte) 2, startX, startY + 1, (byte) 2);
            g.drawRegion(wordPic, 99, 24, 13, 12, Constant.TRANS_NONE, startX, startY, 0);
            startX = startX + 14;
        }
    }

    /**
     * 根据数字和数字图片绘制数字图片
     * @param g
     * @param img   数字的图片
     * @param sNum  数字字符
     * @param byColorType  数字的颜色 1,蓝色，2，白色
     * @param iStartX 绘制开始位置
     * @param iStartY
     * @param numSize  数字的大小（大数字，小数字）；
     * @return
     */
    public static int drawNumPic(Graphics g, Image img, String sNum, byte byColorType, int iStartX, int iStartY, byte numSize) {
        int iPicNumStartX = 0;
        String numeric;
        if (numSize == 1) {
            if (byColorType == 2) {
                iPicNumStartX = 50;
            }
            for (byte i = 0; i < sNum.length(); i++) {
                numeric = sNum.substring(i, i + 1);
                if (numeric.equals("/")) {
                    g.drawRegion(img, 100, 0, 5, 7, Constant.TRANS_NONE, iStartX, iStartY, 0);
                } else {
                    g.drawRegion(img, iPicNumStartX + Byte.parseByte(numeric) * 5, 0, 5, 7, Constant.TRANS_NONE, iStartX, iStartY, 0);
                }
                iStartX = iStartX + 4;
            }
        } else if (numSize == 2) {
            if (byColorType == 2) {
                iPicNumStartX = 70;
            }
            for (byte i = 0; i < sNum.length(); i++) {
                numeric = sNum.substring(i, i + 1);
                if (numeric.equals("/")) {
                    g.drawRegion(img, 150, 0, 5, 7, Constant.TRANS_NONE, iStartX, iStartY, 0);
                    iStartX = iStartX + 6;
                } else if (numeric.equals("%")) {
                    g.drawRegion(img, 140, 0, 10, 9, Constant.TRANS_NONE, iStartX, iStartY, 0);
                    iStartX = iStartX + 10;
                } else {
                    g.drawRegion(img, iPicNumStartX + Byte.parseByte(numeric) * 7, 0, 7, 9, Constant.TRANS_NONE, iStartX, iStartY, 0);
                    iStartX = iStartX + 6;
                }
                
            }
        }
        return iStartX + 1;
    }

    /**
     * 进一取整
     * @param dividend 被除数
     * @param divisor  除数
     * @return
     */
    public static int ceil(int dividend, int divisor) {
        return dividend % divisor == 0 ? dividend / divisor : dividend / divisor + 1;
    }

    /**
     * 把铜币转为金币和银币
     * @param copper 铜币
     * @return
     */
    public static String moneyConvert(long copper) {
        if (copper <= 0) {
            return "0铜";
        }
        String temp = "";
        byte byPre = 0;
        if (copper >= 10000) {
            temp = temp + String.valueOf(copper / 10000) + "金";
            copper = copper % 10000;
            byPre = 1;
        }
        if (copper >= 100) {
            temp = temp + String.valueOf(copper / 100) + "银";
            copper = copper % 100;
            byPre = 1;
        }
        if (copper > 0 || (copper == 0 && byPre == 0)) {
            temp = temp + String.valueOf(copper) + "铜";
        }
        return temp;
    }

    /**
     * 绘制气血经验条
     * @param g
     * @param iBloodColor   血条的颜色
     * @param iSpaceColor  空格的颜色
     * @param iStripLength   血条的长度
     * @param iMaxValue    最大值
     * @param iCurrentValue  当前值
     * @param iHeight  高度
     * @param iStartX  起始位置
     * @param iStartY
     */
    public static void drawBloodStrip(Graphics g, int iBloodColor, int iSpaceColor, int iStripLength, int iMaxValue, int iCurrentValue, int iHeight, int iStartX, int iStartY) {
        if (iCurrentValue <= 0) {
            if (iSpaceColor < 0) {
                return;
            }
            setColor(g, iSpaceColor);
            g.fillRect(iStartX, iStartY, iStripLength, iHeight);
        } else if (iCurrentValue == iMaxValue) {
            setColor(g, iBloodColor);
            g.fillRect(iStartX, iStartY, iStripLength, iHeight);
        } else {
            int length = (iCurrentValue * iStripLength) / iMaxValue;
            setColor(g, iBloodColor);
            g.fillRect(iStartX, iStartY, length, iHeight);
            if (iSpaceColor > -1) {
                setColor(g, iSpaceColor);
                g.fillRect(iStartX + length, iStartY, iStripLength - length, iHeight);
            }
        }
    }

    /**
     * 绘制气血经验条
     * @param g
     * @param iBloodColor   血条的颜色
     * @param iSpaceColor  空格的颜色
     * @param iStripLength   血条的长度
     * @param iMaxValue    最大值
     * @param iCurrentValue  当前值
     * @param iHeight  高度
     * @param iStartX  起始位置
     * @param iStartY
     */
    public static void drawBloodStrip(Graphics g, int iBloodColor, int iSpaceColor, int iStripLength, long iMaxValue, long iCurrentValue, int iHeight, int iStartX, int iStartY) {
        if (iCurrentValue <= 0) {
            if (iSpaceColor < 0) {
                return;
            }
            setColor(g, iSpaceColor);
            g.fillRect(iStartX, iStartY, iStripLength, iHeight);
        } else if (iCurrentValue == iMaxValue) {
            setColor(g, iBloodColor);
            g.fillRect(iStartX, iStartY, iStripLength, iHeight);
        } else {
            int length = (int) ((iCurrentValue * iStripLength) / iMaxValue);
            setColor(g, iBloodColor);
            g.fillRect(iStartX, iStartY, length, iHeight);
            if (iSpaceColor > -1) {
                setColor(g, iSpaceColor);
                g.fillRect(iStartX + length, iStartY, iStripLength - length, iHeight);
            }
        }
    }

    /**
     * 通过职业的ID获得职业的名称
     * @param byJobID:
     * @return
     */
    public static String getJobName(byte byJobID) {
        switch (byJobID) {
            case Constant.PLAYER_OCCUPTION_ASSASSIN:
                return "刺客";
            case Constant.PLAYER_OCCUPTION_MASTER:
                return "术士";
            case Constant.PLAYER_OCCUPTION_SWORD:
                return "武士";
            default:
                return "";
        }
    }

    /** 实现线的上下抖动效果
     * @param 线移动的目标方向，1, 向下，2向上, 0 iArray[0]
     * @param iState 线移动的方向，1,向上，2 向下 1 iArray[1]
     * @param 目标位置   2 iArray[2]
     * @param 抖动的偏移 3 iArray[3]
     * @param 第一次速度 4 iArray[4]
     * @param 第二次速度  5 iArray[4]
     */
    public static int updateLinePos(int[] iArray, int iPositionY) {
        if (iArray == null || iArray[1] == 0) {
            return iPositionY;
        }
        //向下
        if (iArray[0] == 1) {
            if (iArray[1] == 1) {
                if (iPositionY + iArray[4] >= iArray[2] + iArray[3]) {
                    iPositionY = iArray[2] + iArray[3];
                    iArray[1] = 2;
                } else {
                    iPositionY += iArray[4];
                }
            } else if (iArray[1] == 2) {
                if (iPositionY - iArray[5] <= iArray[2]) {
                    iPositionY = iArray[2];
                    iArray[1] = 0;
                } else {
                    iPositionY -= iArray[5];
                }
            }
        } else {
            //向上
            if (iArray[1] == 1) {
                if (iPositionY - iArray[4] <= iArray[2] - iArray[3]) {
                    iPositionY = iArray[2] - iArray[3];
                    iArray[1] = 2;
                } else {
                    iPositionY -= iArray[4];
                }
            } else if (iArray[1] == 2) {
                if (iPositionY + iArray[5] >= iArray[2]) {
                    iPositionY = iArray[2];
                    iArray[1] = 0;
                } else {
                    iPositionY += iArray[5];
                }
            }
        }
        return iPositionY;
    }

    /**
     * 根据任务的状态绘制任务的图标
     * @param g
     * @param taskState
     * @param taskIcon
     * @param startX
     * @param startY
     * 0---- 表示未接任务
     *1----  已接任务.没有完成
     *2----- 失败任务
     *3----- 完成任务
     *4----- 终结任务
     */
    public static void drawTaskIcon(Graphics g, byte taskState, Image taskIcon, int startX, int startY) {
        switch (taskState) {
            case 0:
                g.drawRegion(taskIcon, 27, 0, 16, 15, Constant.TRANS_NONE, startX, startY, 0);
                break;
            case 1:
                g.drawRegion(taskIcon, 27, 33, 16, 15, Constant.TRANS_NONE, startX, startY, 0);
                break;
            case 2:
                g.drawRegion(taskIcon, 27, 33, 16, 15, Constant.TRANS_NONE, startX, startY, 0);
                break;
            case 3:
                g.drawRegion(taskIcon, 27, 17, 16, 15, Constant.TRANS_NONE, startX, startY, 0);
                break;
            case 4:
                g.drawRegion(taskIcon, 27, 33, 16, 15, Constant.TRANS_NONE, startX, startY, 0);
                break;
        }
    }

    /**
     * 绘制两个蓝色的选择条，两边有箭头
     * @param g
     * @param mask  蓝色的遮罩图片
     * @param arrow  箭头图片(null为不要绘制箭头)
     * @param changeArrow 改变箭头的位置（使箭头动起来 ）
     * @param gap  两个选择线的距离
     * @param startX  选择线开始位置(以上面的选择条的底线为准)
     * @param startY
     * @param width   宽度
     */
    public static void drawGapSlectMask(Graphics g, Image mask, Image arrow, boolean changeArrow, int gap, int startX, int startY, int width) {
        drawSelectMask(g, (byte) 1, mask, startX, startY, width);
        drawSelectMask(g, (byte) 2, mask, startX, startY + gap, width);
        if (arrow != null) {
            //箭头
            drawArrow(g, arrow, (byte) 2, changeArrow ? startX + 12 : startX + 10, startY + ((gap - 7) >> 1));
            drawArrow(g, arrow, (byte) 1, changeArrow ? startX + width - 17 : startX + width - 15, startY + ((gap - 7) >> 1));
        }
    }

    /**
     * 产生一个蓝色的选择条小图片d
     */
    public static Image makeBlueMask() {
        try {
            return Tools.createPicFromGrayscale(ResManager.createImage(90000029), 0x0099ff); //蓝色光图
        } catch (Exception e) {
            if (Constant.DEBUG) {
                e.printStackTrace();
            }
        }
        return null;
    }

    /**
     * 绘制弹出一个圆矩形的弹出操作界面
     * @param g
     * @param frameBorder  园矩形的边框
     * @param bgColor  园矩形的背景颜色
     * @param lineColor 文字背景颜色
     * @param sOpArray  操作选项数组
     * @param width   宽度
     * @param lineHeight  行高(黑色部分)
     * @param iGaps  间隔
     * @param fontColor  字体颜色
     * @param selectColor  选中后的字体颜色
     * @param bySelectIndex  选中索引
     * @param iOffsetX  偏移坐标(以正中心为准)(0则左右居中显示)
     * @param iOffsetY  偏移坐标(以正中心为准)(0则上下居中显示)
     */
    public static void drawPopOperation(Graphics g, Image frameBorder, int bgColor, int lineColor, String[] sOpArray, int width, int lineHeight, int iGaps, int fontColor, int selectColor, byte bySelectIndex, int iOffsetX, int iOffsetY) {
        if (sOpArray == null || sOpArray.length < 1) {
            return;
        }
        int startX = Constant.UI_START_X + ((Constant.DRAW_WIDTH - width) >> 1) + iOffsetX;
        int startY;
        //#if NOKIA_S60V5
         startY = Constant.UI_START_Y + ((Constant.END_LINE - (sOpArray.length * (lineHeight + iGaps) + iGaps)) >> 1) + iOffsetY;
        //#else
//#        startY = Constant.UI_START_Y + ((Constant.DRAW_HEIGHT - (sOpArray.length * (lineHeight + iGaps) + iGaps)) >> 1) + iOffsetY;
        //#endif
        drawRoundRect(g, frameBorder, bgColor, width, sOpArray.length * (lineHeight + iGaps) + iGaps, startX, startY);
        setColor(g, fontColor);
        startY = startY + iGaps;
        for (byte i = 0; i < sOpArray.length; i++) {
            setColor(g, lineColor);
            g.fillRect(startX + 1, startY, width - 3, lineHeight);
            if (i + 1 != bySelectIndex) {
                Tools.setColor(g, fontColor);
            } else {
                Tools.setColor(g, selectColor);
            }
            g.drawString(sOpArray[i], startX + ((width - Constant.FONT_SMALL.stringWidth(sOpArray[i])) >> 1), startY + (lineHeight - Constant.FONT_SMALL_HEIGHT >> 1), 0);
            startY = startY + iGaps + lineHeight;
        }
    }
    
    public static int[][] getPopOperationRect(Image frameBorder, int bgColor, int lineColor, String[] sOpArray, int width, int lineHeight, int iGaps, int fontColor, int selectColor, byte bySelectIndex, int iOffsetX, int iOffsetY) {
        if (sOpArray == null || sOpArray.length < 1) {
            return null;
        }
        int startX = Constant.UI_START_X + ((Constant.DRAW_WIDTH - width) >> 1) + iOffsetX;
        int startY;
        //#if NOKIA_S60V5
         startY = Constant.UI_START_Y + ((Constant.END_LINE - (sOpArray.length * (lineHeight + iGaps) + iGaps)) >> 1) + iOffsetY;
        //#else
//#        startY = Constant.UI_START_Y + ((Constant.DRAW_HEIGHT - (sOpArray.length * (lineHeight + iGaps) + iGaps)) >> 1) + iOffsetY;
        //#endif
//        drawRoundRect(g, frameBorder, bgColor, width, sOpArray.length * (lineHeight + iGaps) + iGaps, startX, startY);
//        setColor(g, fontColor);
        startY = startY + iGaps;
        int[][] rects = new int[sOpArray.length][];
        for (byte i = 0; i < sOpArray.length; i++) {
//            setColor(g, lineColor);
//            g.fillRect(startX + 1, startY, width - 3, lineHeight);
//            if (i + 1 != bySelectIndex) {
//                Tools.setColor(g, fontColor);
//            } else {
//                Tools.setColor(g, selectColor);
//            }
//            g.drawString(sOpArray[i], startX + ((width - Constant.FONT_SMALL.stringWidth(sOpArray[i])) >> 1), startY + (lineHeight - Constant.FONT_SMALL_HEIGHT >> 1), 0);
        	rects[i] = new int[]{120,startY,120,iGaps + lineHeight};
            startY = startY + iGaps + lineHeight;
        }
        return rects;
    }

    /**
     * 数字输入框
     * @param g
     * @param bgMask  背景遮罩层拼接图片
     * @param byBgTileDerection 拼接图片拼接方向(1,横向，2纵向)
     * @param width  宽度
     * @param height  高度
     * @param popUpFrame  弹出层边框图片
     * @param button  弹出层确认取消按钮图片
     * @param popUpBgColor  弹出层背景颜色
     * @param popUpTitle  弹出层提示标题
     * @param inputWidth  输入框宽度
     * @param inputHeight 输入框高度
     * @param inputNum 输入框现实的数字(-1 为不显示)
     * @param bShowFlash  当前是否显示闪烁符号
     * @param startX 弹出层开始位置
     * @param startY 
     */
    public static void drawInputCanvas(Graphics g, Image bgMask, byte byBgTileDerection, int width, int height, Image popUpFrame, Image buttonLeft, int imgLeftStartX, int imgLeftStartY, int buttonLeftW, int buttonLeftH, Image buttonRight, int imgRightStartX, int imgRightStartY, int buttonRightW, int buttonRightH, int popUpBgColor, String popUpTitle, int inputWidth, int inputHeight, int inputNum, boolean bShowFlash, int startX, int startY) {
        //背景遮罩层
        if (bgMask != null) {
            if (byBgTileDerection == 2) {
                //#if NOKIA_S60V5
                 drawTilePic(g, (byte) 2, Constant.UI_START_X, Constant.UI_START_Y, Constant.END_LINE, bgMask, 0, 0, Constant.DRAW_WIDTH, 10, Constant.TRANS_NONE);
                //#else
//#                drawTilePic(g, (byte) 2, Constant.UI_START_X, Constant.UI_START_Y, Constant.DRAW_HEIGHT, bgMask, 0, 0, Constant.DRAW_WIDTH, 10, Constant.TRANS_NONE);
                //#endif
            } else {
                drawTilePic(g, (byte) 1, Constant.UI_START_X, Constant.UI_START_Y, Constant.DRAW_WIDTH, bgMask, 0, 0, 10, Constant.DRAW_HEIGHT, Constant.TRANS_NONE);
            }
        }
        drawPopUp(g, (byte) 4, startX, startY, width, height, popUpFrame, popUpBgColor, buttonLeft, imgLeftStartX, imgLeftStartY, buttonLeftW, buttonLeftH, buttonRight, imgRightStartX, imgRightStartY, buttonRightW, buttonRightH, popUpTitle, null);
        //会是输入框
        g.setColor(0xFFFFFF);
        g.fillRect(startX + ((width - inputWidth) >> 1), startY + 31, inputWidth, inputHeight);
        g.setColor(0x000000);
        g.drawRect(startX + ((width - inputWidth) >> 1), startY + 31, inputWidth, inputHeight);
        //绘制用户输入的文字
        if (inputNum == -1) {
            if (bShowFlash) {
                g.drawChar('|', startX + ((width - inputWidth) >> 1) + 3, startY + 31 + ((inputHeight - Constant.FONT_SMALL_HEIGHT) >> 1), 0);
            }
        } else {
            g.drawString(String.valueOf(inputNum), startX + ((width - inputWidth) >> 1) + 3, startY + 31 + ((inputHeight - Constant.FONT_SMALL_HEIGHT) >> 1), 0);
            if (bShowFlash) {
                g.drawChar('|', startX + ((width - inputWidth) >> 1) + 4 + Constant.FONT_SMALL.stringWidth(String.valueOf(inputNum)), startY + 31 + ((inputHeight - Constant.FONT_SMALL_HEIGHT) >> 1), 0);
            }
        }
    }

    /**
     * 更新输入界面
     * @param inputNum  已经输入的数字(-1表示没有输入数字)
     * @param iMaxNum  最大数字限制
     * @return 
     */
    public static int updateInputCanvas(int inputNum, int iMaxNum) {
        if (MainCanvas.keyPressedLogic(Constant.GAME_KEY_0, false)) {
            inputNum = (inputNum == -1 ? 0 : inputNum) * 10 + 0;
        } else if (MainCanvas.keyPressedLogic(Constant.GAME_KEY_1, false)) {
            inputNum = (inputNum == -1 ? 0 : inputNum) * 10 + 1;
        } else if (MainCanvas.keyPressedLogic(Constant.GAME_KEY_2, false)) {
            inputNum = (inputNum == -1 ? 0 : inputNum) * 10 + 2;
        } else if (MainCanvas.keyPressedLogic(Constant.GAME_KEY_3, false)) {
            inputNum = (inputNum == -1 ? 0 : inputNum) * 10 + 3;
        } else if (MainCanvas.keyPressedLogic(Constant.GAME_KEY_4, false)) {
            inputNum = (inputNum == -1 ? 0 : inputNum) * 10 + 4;
        } else if (MainCanvas.keyPressedLogic(Constant.GAME_KEY_5, false)) {
            inputNum = (inputNum == -1 ? 0 : inputNum) * 10 + 5;
        } else if (MainCanvas.keyPressedLogic(Constant.GAME_KEY_6, false)) {
            inputNum = (inputNum == -1 ? 0 : inputNum) * 10 + 6;
        } else if (MainCanvas.keyPressedLogic(Constant.GAME_KEY_7, false)) {
            inputNum = (inputNum == -1 ? 0 : inputNum) * 10 + 7;
        } else if (MainCanvas.keyPressedLogic(Constant.GAME_KEY_8, false)) {
            inputNum = (inputNum == -1 ? 0 : inputNum) * 10 + 8;
        } else if (MainCanvas.keyPressedLogic(Constant.GAME_KEY_9, false)) {
            inputNum = (inputNum == -1 ? 0 : inputNum) * 10 + 9;
        } else if (MainCanvas.keyPressedLogic(Constant.GAME_KEY_LEFT, true)) {
            if (inputNum > 10) {
                inputNum = inputNum / 10;
            } else {
                inputNum = -1;
            }
        }
        if (inputNum > iMaxNum) {
            inputNum = iMaxNum;
        }
        return inputNum;
    }

    /**
     * 绘制物品
     * @param g
     * @param items   物品类
     * @param itemBg  物品框的背景
     * @param levelNumPic  物品的等级图片
     * @param arrowPic   箭头图片
     * @param pagePic 翻页的数字图片
     * @param startX  开始位置
     * @param startY
     * @param page  页数
     */
    public static void drawPackageBox(Graphics g, Goods items, Image pagePic, Image arrowPic, String tips, int startX, int startY, short page, short totalPage, byte[] byShowMask, Image maskPic) {
        //绘制包裹中的道drawPackageBox具
        if (items == null) {
            return;
        }
        int iStartX = startX;
        int iStartY = startY;
        //格被选中，且有物品
        short index = 0;
        for (byte i = 0; i < 28; i++) {
            //物品放置的索引位置
            index = (short) ((page - 1) * 28 + i);
            if (i % 7 == 0) {
                iStartX = startX;
            }
            items.drawGoods(g, iStartX, iStartY, index);
            if (byShowMask != null && index < byShowMask.length) {
                g.drawImage(maskPic, iStartX + 1, iStartY + 1, 0);
            }
            //绘制的格子
            if (i % 7 == 6) {
                //#if NOKIA_S60V5
                 iStartY = iStartY + 44;
                //#else
//#                iStartY = iStartY + 32;
                //#endif
            }
            //#if NOKIA_S60V5
             iStartX = iStartX + 44;
            //#else
//#            iStartX = iStartX + 32;
            //#endif

        }
        //#if NOKIA_S60V5
         iStartX = iStartX + 177;
         //绘制翻页
         iStartX = startX + 305 - Tools.getPageStrWidth((short) Tools.ceil(items.getMaxColumNum(), 28), page);
         Tools.drawPage(g, totalPage, page, pagePic, arrowPic, iStartX, iStartY + ((Constant.FONT_SMALL_HEIGHT - 9) >> 1));
         g.setColor(0x333333);
         g.drawString(tips, iStartX - 2, iStartY, g.RIGHT | g.TOP);
        //#else
//#        iStartY = startY + 129;
//#        //绘制翻页
//#        iStartX = startX + 219 - Tools.getPageStrWidth((short) Tools.ceil(items.getMaxColumNum(), 28), page);
//#        Tools.drawPage(g, totalPage, page, pagePic, arrowPic, iStartX, iStartY + ((Constant.FONT_SMALL_HEIGHT - 9) >> 1));
//#        if (tips != null) {
//#            g.setColor(0x333333);
//#            g.drawString(tips, iStartX - 2, iStartY, g.RIGHT | g.TOP);
//#        }
        //#endif
    }

    /**
     * 绘制一行有颜色的字
     */
    public static void drawColorString(Graphics g, String sRowText, int oldColor, int startX, int startY) {
        if (sRowText.charAt(0) == '<') {
            int color = getColor(sRowText.charAt(1));
            if (color > -1) {
                setColor(g, color);
            }
            g.drawString(sRowText.substring(2, sRowText.length()), startX, startY, 0);
            Tools.setColor(g, oldColor);
        } else {
            g.drawString(sRowText, startX, startY, 0);
        }
    }
    
    public static void drawColorString(Graphics g, String sRowText, int oldColor, int shawdowColor, int startX, int startY, int achor) {
        if (sRowText == null || sRowText.length() < 1) {
            return;
        }
        Tools.setColor(g, oldColor);
        if (sRowText.charAt(0) == '<') {
            int color = getColor(sRowText.charAt(1));
            color = color == -1 ? oldColor : color;
            if (shawdowColor == -1) {
                Tools.setColor(g, color);
                g.drawString(sRowText.substring(2, sRowText.length()), startX, startY, achor);
            } else {
                Tools.drawShadowString(g, (byte) 1, sRowText.substring(2, sRowText.length()), startX, startY, color, shawdowColor, achor);
            }
        } else {
            g.drawString(sRowText, startX, startY, achor);
        }
    }

    /**
     * 判断一个数是是否是奇数
     * @param i
     * @return
     */
    public static boolean isOdd(int i) {
        return (i & 1) != 0;
    }

    /**
     * 判端一个字符串是否全部是数字
     * @param str
     * @return
     */
    public static boolean isNumeric(String str) {
        if (str == null || str.equals("")) {
            return false;
        }
        for (int i = str.length(); --i >= 0;) {
            if (!Character.isDigit(str.charAt(i))) {
                return false;
            }
        }
        return true;
    }

    /**
     * 判断一个字符串是否全部是数字或者字母
     */
    public static boolean isNumOrletters(String str) {
        char[] charstr = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',//
            'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',//
            'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't',//
            'u', 'v', 'w', 'x', 'y', 'z',//
            'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J',//
            'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T',//
            'U', 'V', 'W', 'X', 'Y', 'Z',//
        };
        /////////
        if (str == null || str.length() < 1) {
            return false;
        }
        int length = str.length();
        char tempChar;
        boolean isgood = false;
        for (int i = 0; i < length; i++) {
            isgood = false;
            tempChar = str.charAt(i);
            for (int j = 0; j < charstr.length; j++) {
                if (tempChar == charstr[j]) {
                    isgood = true;
                }
            }
            if (!isgood) {
                return false;
            }
        }
        //////////////
        return true;
    }
    /*
     * 查询是否为本地avatar
     */
    //#if NOKIA_S40V3  || NORMAL_240_400 || MOT0 || K790
//#      private static int[] shLocalAvatarId = new int[]{1,3, 6,8,9,11,12,13,14,19,25,27, 31,37,38,40,41,42,54,55,57,61,67,80,81,87,89,189,217,296,297,298,299,346,217,220,235,256,276, 287,288,290,291,294,321,322,323, 329,331,333,338,340,344,341,348,351,354,355,356,357,358,359,360,361,362,364,365,366,367,368,369,370,371,372,373,375,376,377,378,379,382,383,389,390,391,392,399,404,405,406,407,420,423,424,425,426,427,438,437,439,441,6403, 500008, 620008, 699999,6000001,6000002,6000003,6000004,6000005,6000006};
    //#else
    private static int[] shLocalAvatarId = new int[]{1, 3, 6, 8, 9, 11, 12, 13, 14, 19, 25, 27, 31, 37, 38, 40, 41, 42, 54, 55, 57, 61, 67, 80, 81, 84, 85, 86, 91, 92, 93, 94, 95, 111, 112, 116, 117, 189, 217, 296, 297, 298, 299, 346, 217, 220, 221, 234, 235, 256, 274, 276, 287, 288, 290, 291, 294, 300, 321, 329, 323, 331, 333, 338, 340, 344, 341, 348, 351, 354, 355, 356, 357, 358, 359, 360, 361, 362, 364, 365, 366, 367, 368, 369, 370, 371, 372, 373, 374, 375, 376, 377, 378, 379, 382, 383, 384, 385, 386, 387, 388, 389, 390, 391, 392, 399, 400, 401, 402, 403, 404, 405, 406, 407, 408, 409, 410, 411, 412, 413, 414, 415, 416, 417, 418, 419, 420, 421, 423, 424, 425, 426, 427, 428, 429, 430, 431, 437, 438, 439, 441, 6403, 500008, 620008, 699999, 5800001};
    //#endif

    /**
     * 判读是否是查询是否为本地
     * @param avatarid
     * @return
     */
    public static boolean isLocalAvatar(int avatarid) {
        for (int i = shLocalAvatarId.length - 1; i >= 0; i--) {
            if (avatarid == shLocalAvatarId[i]) {
                return true;
            }
        }
        return false;
    }
    
    public static byte getClientDirection(byte type) {
        switch (type) {
            case 0:
                return 1;
            case 1:
                return 0;
        }
        return type;
    }

    /**
     * 检测某个数字是否在数组中
     * @param value
     * @param iArray
     * @return
     */
    public static int inArray(int value, int[] iArray) {
        for (int i = 0; i < iArray.length; i++) {
            if (iArray[i] == value) {
                return i;
            }
        }
        return -1;
    }
    
    public static int inArray(byte value, byte[] byArray) {
        for (int i = 0; i < byArray.length; i++) {
            if (byArray[i] == value) {
                return i;
            }
        }
        return -1;
    }
    
    public static int inArray(short value, short[] shArray) {
        for (int i = 0; i < shArray.length; i++) {
            if (shArray[i] == value) {
                return i;
            }
        }
        return -1;
    }
    
    public static int inArray(long value, long[] lArray) {
        for (int i = 0; i < lArray.length; i++) {
            if (lArray[i] == value) {
                return i;
            }
        }
        return -1;
    }

    /**
     * 背包中已经被选中的物品
     */
    public static void setBagSelectedItemsIndex(short[] scrIndex, byte[][] destIndex) {
        if (scrIndex == null || scrIndex.length < 1 || destIndex == null || destIndex.length < 1) {
            return;
        }
        for (byte i = 0; i < scrIndex.length; i += 2) {
            if (scrIndex[i] != -1) {
                destIndex[scrIndex[i]][scrIndex[i + 1]] = 1;
            }
        }
    }

    /**
     * 为玩家走路临时设定的方向选择器确定方案后决定是否保留
     * @param direct
     * @param type
     * @return
     */
    public static int getDirection(int direct, int type) {
        switch (direct) {
            case Constant.PLAYER_DIRECTION_UP:
                if (type == Constant.PLAYER_DIRECTION_TYPE_X) {
                    return 0;
                } else {
                    return 1;
                }
            case Constant.PLAYER_DIRECTION_DOWN:
                if (type == Constant.PLAYER_DIRECTION_TYPE_X) {
                    return 0;
                } else {
                    return -1;
                }
            case Constant.PLAYER_DIRECTION_LEFT:
                if (type == Constant.PLAYER_DIRECTION_TYPE_X) {
                    return -1;
                } else {
                    return 0;
                }
            case Constant.PLAYER_DIRECTION_RIGHT:
                if (type == Constant.PLAYER_DIRECTION_TYPE_X) {
                    return 1;
                } else {
                    return 0;
                }
        }
        return 0;
    }

    /**
     * 
     * @param typex
     * @param typey
     * @return
     */
    public static byte getEightRealDirection(int typex, int typey) {
        switch (typex) {
            case 0:
                if (typey == 1) {
                    return Constant.PLAYER_DIRECTION_DOWN;
                } else if (typey == -1) {
                    return Constant.PLAYER_DIRECTION_UP;
                }
            case 1:
                if (typey == 0) {
                    return Constant.PLAYER_DIRECTION_RIGHT;
                } else if (typey == 1) {
                    return Constant.PLAYER_DIRECTION_DOWN_RIGHT;
                } else if (typey == -1) {
                    return Constant.PLAYER_DIRECTION_UP_RIGHT;
                }
            case -1:
                if (typey == 0) {
                    return Constant.PLAYER_DIRECTION_LEFT;
                } else if (typey == 1) {
                    return Constant.PLAYER_DIRECTION_DOWN_LEFT;
                } else if (typey == -1) {
                    return Constant.PLAYER_DIRECTION_UP_LEFT;
                }
        }
        return Constant.PLAYER_DIRECTION_DOWN;
    }
    
    public static String getRoleJob(String job) {
        job = job.trim();
        if (job.equals("Paladin")) {
            return String.valueOf(Constant.PLAYER_OCCUPTION_ASSASSIN);
        } else if (job.equals("Paladin1")) {
            return String.valueOf(Constant.PLAYER_OCCUPTION_ASSASSIN);
        } else if (job.equals("Hercules")) {
            return String.valueOf(Constant.PLAYER_OCCUPTION_SWORD);
        } else if (job.equals("Hercules1")) {
            return String.valueOf(Constant.PLAYER_OCCUPTION_SWORD);
        } else if (job.equals("Master")) {
            return String.valueOf(Constant.PLAYER_OCCUPTION_MASTER);
        } else if (job.equals("Master1")) {
            return String.valueOf(Constant.PLAYER_OCCUPTION_MASTER);
        }
        return String.valueOf(Constant.PLAYER_OCCUPTION_ASSASSIN);
    }

    /**
     * 求两个正整数之间的随机数
     * @param a int
     * @param b int
     * @return int
     */
    public static final int random(int a, int b) {
        Random rnd = new Random();
        if (a <= b) {
            return Math.abs(rnd.nextInt() % (b - a + 1)) + a;
        } else {
            return Math.abs(rnd.nextInt() % (a - b + 1)) + b;
        }
    }
    
    public static void resetAniArray(int value, int[] iArray) {
        for (int i = 0; i < iArray.length; i++) {
            iArray[i] = value;
        }
    }

    /**
     * 获得npc下一个移动目的地的坐标
     * @param iOrig  npc中心点坐标
     * @param iCurr  npc当前坐标
     * @param iRadius  npc移动的x y轴的半径(npc移动的范围是矩形)
     * @param iMinMoveDistance   随机出来的坐标和npc当前的坐标的最小距离（是X,Y,不是直线距离）(必须小于npc的移动的半径);
     * @return  获得的位置坐标
     */
    public static int getNpcRodamXY(int iOrig, int iCurr, int iRadius, int iMinMoveDistance) {
        int iMax, iMin;
        //小于最小距离
        if (iCurr + iMinMoveDistance > iOrig + iRadius) {
            iMax = iCurr - iMinMoveDistance;
            iMin = iOrig - iRadius;
        } else if (iCurr - iMinMoveDistance < iOrig - iRadius) {
            iMin = iCurr + iMinMoveDistance;
            iMax = iOrig + iRadius;
        } else {
            iMax = iOrig + iRadius;
            iMin = iOrig - iRadius;
        }
        return random(iMin, iMax);
    }

    /**
     * 平方
     * @param num
     * @return
     */
    public static int square(int num) {
        return num * num;
    }

    /**
     * 绘制物品框
     * @param g
     * @param bgPic
     * @param startX
     * @param startY 
     */
    public static void drawItemBg(Graphics g, Image bgPic, byte byColor, int startX, int startY) {
        g.drawImage(bgPic, startX, startY, 0);
        g.drawRegion(bgPic, 0, 0, 15, 15, Constant.TRANS_MIRROR, startX + 15, startY, 0);
        g.drawRegion(bgPic, 0, 0, 15, 15, Constant.TRANS_MIRROR_ROT180, startX, startY + 15, 0);
        g.drawRegion(bgPic, 0, 0, 15, 15, Constant.TRANS_ROT180, startX + 15, startY + 15, 0);
        if (byColor == -1) {
            return;
        }
        Tools.setColor(g, Goods.getGoodsNameColor(byColor));
        g.drawRect(startX + 1, startY + 1, 27, 27);
        //左上
        g.drawRect(startX + 1, startY + 1, 1, 2);
        g.drawRect(startX + 1, startY + 1, 2, 1);
        //左下
        g.drawRect(startX + 1, startY + 26, 1, 2);
        g.drawRect(startX + 1, startY + 27, 2, 1);
        //右上
        g.drawRect(startX + 26, startY + 1, 2, 1);
        g.drawRect(startX + 27, startY + 1, 1, 2);
        //右下
        g.drawRect(startX + 27, startY + 26, 1, 2);
        g.drawRect(startX + 26, startY + 27, 2, 1);
    }

    //#if NOKIA_S60V5
     /**
      * 绘S60v5制物品框
      * @param g
      * @param bgPic
      * @param startX
      * @param startY
      */
     public static void drawS60V5ItemBg(Graphics g, Image bgPic, Image boderPic, byte byColor, int startX, int startY) {
         g.drawRegion(boderPic, 0, 0, 17, 17, Constant.TRANS_NONE, startX, startY, 0);
         g.drawRegion(boderPic, 19, 0, 24, 24, Constant.TRANS_NONE, startX + 17, startY, 0);
         g.drawRegion(boderPic, 0, 0, 17, 17, Constant.TRANS_ROT180, startX + 24, startY + 24, 0);
         g.drawRegion(boderPic, 19, 0, 24, 24, Constant.TRANS_ROT180, startX, startY + 17, 0);
         startX += 6;
         startY += 6;
         g.drawImage(bgPic, startX, startY, 0);
         g.drawRegion(bgPic, 0, 0, 15, 15, Constant.TRANS_MIRROR, startX + 15, startY, 0);
         g.drawRegion(bgPic, 0, 0, 15, 15, Constant.TRANS_MIRROR_ROT180, startX, startY + 15, 0);
         g.drawRegion(bgPic, 0, 0, 15, 15, Constant.TRANS_ROT180, startX + 15, startY + 15, 0);
         if (byColor == -1) {
             return;
         }
         Tools.setColor(g, Goods.getGoodsNameColor(byColor));
         g.drawRect(startX + 1, startY + 1, 27, 27);
         //左上
         g.drawRect(startX + 1, startY + 1, 1, 2);
         g.drawRect(startX + 1, startY + 1, 2, 1);
         //左下
         g.drawRect(startX + 1, startY + 26, 1, 2);
         g.drawRect(startX + 1, startY + 27, 2, 1);
         //右上
         g.drawRect(startX + 26, startY + 1, 2, 1);
         g.drawRect(startX + 27, startY + 1, 1, 2);
         //右下
         g.drawRect(startX + 27, startY + 26, 1, 2);
         g.drawRect(startX + 26, startY + 27, 2, 1);
     }
 
     /*
      * 绘制S60V5头像
      * @param g
      * @param rect头像边框
      * @param head头像
      * @param x
      * @param y
      */
     public static void drawHead(Graphics g, Image rect, Image head, int x, int y) {
         g.drawRegion(rect, 0, 0, 17, 17, Constant.TRANS_NONE, x, y, 0);
         g.drawRegion(rect, 29, 0, 14, 14, Constant.TRANS_NONE, x + 17, y, 0);
         g.drawRegion(rect, 0, 0, 17, 17, Constant.TRANS_ROT180, x + 14, y + 14, 0);
         g.drawRegion(rect, 29, 0, 14, 14, Constant.TRANS_ROT180, x, y + 17, 0);
         g.drawImage(head, x + 6, y + 6, 0);
     }
    //#endif
    /**
     * 绘制
     * @param g
     * @param str1
     * @param str2
     * @param color
     */
    public static void drawStrButton(Graphics g, String str1, String str2, int color) {
        int dx = 2;
        int dy = Constant.SCREEN_HEIGHT - Constant.FONT_SMALL_HEIGHT;
        g.setColor(color);
        g.drawString(str1, dx, dy, 0);
        g.drawString(str2, Constant.SCREEN_WIDTH - Constant.FONT_SMALL.stringWidth(str2) - 2, dy, 0);
    }

    /**
     * 根据方向获得循环菜单
     * @param menu
     * @param direct
     */
    public static void changeRoundMenu(int[] menu, byte direct) {
        try {
            int temp = 0;
            //向左
            if (direct == 0) {
                temp = menu[0];
                for (int i = 0; i < menu.length - 1; i++) {
                    menu[i] = menu[i + 1];
                }
                menu[menu.length - 1] = temp;
            } else if (direct == 1)//向右
            {
                temp = menu[menu.length - 1];
                for (int i = menu.length - 1; i > 0; i--) {
                    menu[i] = menu[i - 1];
                }
                menu[0] = temp;
            }
            
        } catch (Exception e) {
            if (Constant.DEBUG) {
                e.printStackTrace();
            }
        }
    }

    /**
     * 图像放缩方法
     * @param src 原始的Image对象
     * @param desW 放缩后的Image的宽度
     * @param desH 放缩后的Image的高度
     * @return 放缩后的Image对象
     */
    public static Image ZoomImage(Image src, int desW, int desH) {
        Image desImg = null;
        int srcW = src.getWidth(); // 原始图像宽
        int srcH = src.getHeight(); // 原始图像高
        int[] srcBuf = new int[srcW * srcH]; // 原始图片像素信息缓存
        src.getRGB(srcBuf, 0, srcW, 0, 0, srcW, srcH);
        // 计算插值表
        int[] tabY = new int[desH];
        int[] tabX = new int[desW];
        int sb = 0;
        int db = 0;
        int tems = 0;
        int temd = 0;
        int distance = srcH > desH ? srcH : desH;
        for (int i = 0; i <= distance; i++) { /* 垂直方向 */
            tabY[db] = sb;
            tems += srcH;
            temd += desH;
            if (tems > distance) {
                tems -= distance;
                sb++;
            }
            if (temd > distance) {
                temd -= distance;
                db++;
            }
        }
        sb = 0;
        db = 0;
        tems = 0;
        temd = 0;
        distance = srcW > desW ? srcW : desW;
        for (int i = 0; i <= distance; i++) { /* 水平方向 */
            tabX[db] = (short) sb;
            tems += srcW;
            temd += desW;
            if (tems > distance) {
                tems -= distance;
                sb++;
            }
            if (temd > distance) {
                temd -= distance;
                db++;
            }
        }
        // 生成放大缩小后图形像素buf
        int[] desBuf = new int[desW * desH];
        int dx = 0;
        int dy = 0;
        int sy = 0;
        int oldy = -1;
        for (int i = 0; i < desH; i++) {
            if (oldy == tabY[i]) {
                System.arraycopy(desBuf, dy - desW, desBuf, dy, desW);
            } else {
                dx = 0;
                for (int j = 0; j < desW; j++) {
                    desBuf[dy + dx] = srcBuf[sy + tabX[j]];
                    dx++;
                }
                sy += (tabY[i] - oldy) * srcW;
            }
            oldy = tabY[i];
            dy += desW;
        }
        // 生成图片
        desImg = Image.createRGBImage(desBuf, desW, desH, true);
        return desImg;
    }

    /**
     * 根据数字和数字图片绘制数字图片
     * @param g
     * @param img
     * @param sNum
     * @param W
     * @param imgStartx
     * @param imgW
     * @param imgH
     * @param iStartX
     * @param iStartY
     * @param anchor
     */
    public static void drawNumPic(Graphics g, Image img, String sNum, int W, int imgStartx,
            int imgW, int imgH, int iStartX, int iStartY, int anchor) {
        byte byNum, i;
        if (Integer.parseInt(sNum) < 0) {
            sNum = "" + 0;
        }
        for (i = 0; i < sNum.length(); i++) {
            byNum = Byte.parseByte(sNum.substring(i, i + 1));
            int numW = 0;
            if (anchor == (g.TOP | g.RIGHT)
                    || anchor == (g.BOTTOM | g.RIGHT)) {
                numW = -((imgW + W) * (sNum.length() - 1 - i));
            } else {
                numW = (imgW + W) * i;
            }
            g.drawRegion(img, imgStartx + byNum * imgW, 0, imgW, imgH, Constant.TRANS_NONE, iStartX + numW, iStartY, anchor);
        }
    }
    //画箭头的左右移动
    public static final int BITS = 6;// 基本不影响精度的情况下尽量小,建议在4~6
    private static final int FIX = 12 - BITS;
    public static final int ONE = 1 << BITS;
    public static final int MASK = ONE - 1;

    /**
     * 定点数取整（四舍五入）
     * @param n 定点数
     * @return 取整的定点数
     */
    public static final int round(int n) {
        return (n + (ONE >> 1)) & ~MASK;
    }

    /**
     * 定点数->整数
     * @param nFP 定点数
     * @return 整数
     */
    public static final int toInt(int nFP) {
        return round(nFP) >> BITS;
//		return nFP >> BITS;
    }
    private static final short[] SINES_X_FP = {0 >> FIX, 71 >> FIX,
        143 >> FIX, 214 >> FIX, 286 >> FIX, 357 >> FIX, 428 >> FIX,
        499 >> FIX, 570 >> FIX, 641 >> FIX, 711 >> FIX, 782 >> FIX,
        852 >> FIX, 921 >> FIX, 991 >> FIX, 1060 >> FIX, 1129 >> FIX,
        1198 >> FIX, 1266 >> FIX, 1334 >> FIX, 1401 >> FIX, 1468 >> FIX,
        1534 >> FIX, 1600 >> FIX, 1666 >> FIX, 1731 >> FIX, 1796 >> FIX,
        1860 >> FIX, 1923 >> FIX, 1986 >> FIX, 2048 >> FIX, 2110 >> FIX,
        2171 >> FIX, 2231 >> FIX, 2290 >> FIX, 2349 >> FIX, 2408 >> FIX,
        2465 >> FIX, 2522 >> FIX, 2578 >> FIX, 2633 >> FIX, 2687 >> FIX,
        2741 >> FIX, 2793 >> FIX, 2845 >> FIX, 2896 >> FIX, 2946 >> FIX,
        2996 >> FIX, 3044 >> FIX, 3091 >> FIX, 3138 >> FIX, 3183 >> FIX,
        3228 >> FIX, 3271 >> FIX, 3314 >> FIX, 3355 >> FIX, 3396 >> FIX,
        3435 >> FIX, 3474 >> FIX, 3511 >> FIX, 3547 >> FIX, 3582 >> FIX,
        3617 >> FIX, 3650 >> FIX, 3681 >> FIX, 3712 >> FIX, 3742 >> FIX,
        3770 >> FIX, 3798 >> FIX, 3824 >> FIX, 3849 >> FIX, 3873 >> FIX,
        3896 >> FIX, 3917 >> FIX, 3937 >> FIX, 3956 >> FIX, 3974 >> FIX,
        3991 >> FIX, 4006 >> FIX, 4021 >> FIX, 4034 >> FIX, 4046 >> FIX,
        4056 >> FIX, 4065 >> FIX, 4074 >> FIX, 4080 >> FIX, 4086 >> FIX,
        4090 >> FIX, 4094 >> FIX, 4095 >> FIX, 4096 >> FIX};

    /**
     * 定点数sin
     * @param angle
     * @return
     */
    public static final int sin(int angle) {
        angle %= 360 << BITS;    // 360 degrees
        if (angle < 0) {
            angle += 360 << BITS;
        }
        if (angle <= 90 << BITS) {
            return SINES_X_FP[toInt(angle)];
        } else if (angle <= 180 << BITS) {
            return SINES_X_FP[180 - toInt(angle)];
        } else if (angle <= 270 << BITS) {
            return -SINES_X_FP[toInt(angle) - 180];
        } else {
            return -SINES_X_FP[360 - toInt(angle)];
        }
    }

    /**
     * @param g
     * @param sMarqueeString  跑马灯文字
     * @param iStartX  //跑马灯起始位置(左边开始)
     * @param iLength //跑马灯长度
     * @param iOffset p跑马灯偏移位置
     * @param byDerection: 跑马灯方向（1,从左向右，2从右向左）
     * @param iColor : 跑马灯文字
     * @param iShadowColor: 文字阴影颜色，没有则为-1
     */
    public static void drawMarquee(Graphics g, String sMarqueeString, int iStartX, int iNowStartX, int iStartY, int iLength, int iColor, int iShadowColor) {
        if (sMarqueeString == null) {
            return;
        }
        int xOld = g.getClipX();
        int yOld = g.getClipY();
        int wOld = g.getClipWidth();
        int hOld = g.getClipHeight();
        g.setClip(iStartX, iStartY - 1, iLength, Constant.FONT_SMALL_HEIGHT + 2);
        if (iShadowColor > -1) {
            drawShadowString(g, (byte) 1, sMarqueeString, iNowStartX, iStartY, iColor, iShadowColor);
        } else {
//            g.setClip(iStartX, iStartY - 1, iLength, Constant.FONT_SMALL_HEIGHT + 2);
            g.setColor(iColor);
            g.drawString(sMarqueeString, iNowStartX, iStartY, 0);
        }
        g.setClip(xOld, yOld, wOld, hOld);
    }

    /**
     * 解析URL
     */
//    public static void getUrl(String url, String str1, String endstr1,
//            String str2, String endstr2, String str3, String endstr3) {
//        boolean colnumStr = false;
//        int colnum = -1, colnum1 = -1, colnum2 = -1, colnum3 = -1, colnum4 = -1, colnum5 = -1;
//        for (int i = 0; i < url.length(); i++) {
//            if (i < url.length() - str1.length() + 1) {
//                if (url.substring(i, i + str1.length()).equals(str1)) {
//                    colnum = i + str1.length();
//                }
//            }
//            if (i < url.length() - endstr1.length() + 1) {
//                if (url.substring(i, i + endstr1.length()).equals(endstr1)) {
//                    colnum1 = i;
//                }
//            }
//            //
//            if (i < url.length() - str2.length() + 1) {
//                if (url.substring(i, i + str2.length()).equals(str2)) {
//                    colnum2 = i + str2.length();
//                }
//            }
//            if (i < url.length() - endstr2.length() + 1) {
//                if (url.substring(i, i + endstr2.length()).equals(endstr2)) {
//                    colnum3 = i;
//                }
//            }
//            //
//            if (i < url.length() - str3.length() + 1) {
//                if (url.substring(i, i + str3.length()).equals(str3)) {
//                    colnum4 = i + str3.length();
//                }
//            }
//            if (i < url.length() - endstr3.length() + 1) {
//                if (url.substring(i, i + endstr3.length()).equals(endstr3)) {
//                    colnum5 = i;
//                }
//            }
//        }
////        Tools.printLog("colnum   " + colnum);
////        Tools.printLog("colnum1   " + colnum1);
////        Tools.printLog("colnum2   " + colnum2);
////        Tools.printLog("colnum3   " + colnum3);
////        Tools.printLog("colnum4   " + colnum4);
////        Tools.printLog("colnum5   " + colnum5);
//        if (colnum != -1 && colnum1 != -1) {
//            Constant.USER_CENTER_SUCCESS = url.substring(colnum, colnum1);
////            Tools.printLog("111  :::  " + url.substring(colnum, colnum1));
//        }
//        if (colnum2 != -1 && colnum3 != -1) {
//            Constant.USER_CENTER_VERSION = url.substring(colnum2, colnum3);
////            Tools.printLog("222  :::  " + url.substring(colnum2, colnum3));
//        }
//        if (colnum4 != -1 && colnum5 != -1) {
//            Constant.USER_CENTER_DOWNLOADADDRESS = url.substring(colnum4, colnum5);
////            Tools.printLog("333  :::  " + url.substring(colnum4, colnum5));
//        }
//    }
    /**
     * 绘制一段带有阴影的文字并且在文字中可以画表情图片
     * @param g
     * @param str
     * @param iOriStartX
     * @param OriStartY
     * @param iFontColor
     * @param iShadowColor
     * @param img
     * @param imgStartX
     * @param imgStartY
     * @param imgStartW
     * @param imgStartH
     * @param colstr
     */
    public static void drawShadowString(Graphics g, String str,
            int iOriStartX, int OriStartY,
            int iFontColor, int iShadowColor,
            Image img, int imgStartX, int imgStartY,
            int imgStartW, int imgStartH, String colstr, String imgId) {
        int length = str.length();
        char tempChar, tempChar1 = ' ';
        int tempLength = 0;
        int charWidth;
        int iStartX = iOriStartX;
        int iStartY = OriStartY;
        boolean bldrawchar = true;
        byte bydrawCount = 0;
        int colnum = -1, colnum1 = -1;//有颜色的字
        boolean colnumStr = false;
        Image imgitem = null;
        int imgitemID = -1;
        if (colstr != null) {
            for (int i = 1; i <= colstr.length(); i++) {
                if (i > str.length()) {
                    break;
                }
                if (str.substring(0, i).equals(colstr.substring(colstr.length() - i, colstr.length()))) {
                    colnumStr = true;
                    colnum1 = i;
                }
            }
        }
        if (imgId != null) {//去掉图片显示
//            if (imgId.length() > 1) {
//                imgitemID = Integer.parseInt(imgId.substring(1, imgId.length()));
//                imgitem = Goods.getGoodsIconFromID(imgitemID);
//            }
        }
        for (int i = 0; i < length; i++) {
            tempChar = str.charAt(i);
            if (i < length - 1) {
                tempChar1 = str.charAt(i + 1);
            }
            if (tempChar == '/') {
                if (tempChar1 == '1'
                        || tempChar1 == '2'
                        || tempChar1 == '3'
                        || tempChar1 == '4'
                        || tempChar1 == '5'
                        || tempChar1 == '6'
                        || tempChar1 == '7'
                        || tempChar1 == '8'
                        || tempChar1 == '9'
                        || tempChar1 == '0'
                        || tempChar1 == '*'
                        || tempChar1 == '#' //                        || tempChar1 == '%'
                        ) {
                    int charTwo = 0;
                    int img_W = 0;
                    if (tempChar1 == '*') {
                        charTwo = Constant.FONT_SMALL.stringWidth("/*0");
                    } else {
                        charTwo = Constant.FONT_SMALL.stringWidth("/10");
                    }
                    if (tempChar1 == '1') {
                        img_W = 0;
                    } else if (tempChar1 == '2') {
                        img_W = imgStartW;
                    } else if (tempChar1 == '3') {
                        img_W = imgStartW * 2;
                    } else if (tempChar1 == '4') {
                        img_W = imgStartW * 3;
                    } else if (tempChar1 == '5') {
                        img_W = imgStartW * 4;
                    } else if (tempChar1 == '6') {
                        img_W = imgStartW * 5;
                    } else if (tempChar1 == '7') {
                        img_W = imgStartW * 6;
                    } else if (tempChar1 == '8') {
                        img_W = imgStartW * 7;
                    } else if (tempChar1 == '9') {
                        img_W = imgStartW * 8;
                    } else if (tempChar1 == '*') {
                        img_W = imgStartW * 9;
                    } else if (tempChar1 == '0') {
                        img_W = imgStartW * 10;
                    } else if (tempChar1 == '#') {
                        img_W = imgStartW * 11;
                    }
//                    else if (tempChar1 == '%') {
//                        img_W = imgStartW * 11;
//                        colnum = i;
//
//                    }
                    bldrawchar = false;
                    bydrawCount = 0;
                    if (img != null) {
                        int img_h = 0;
                        if (Constant.FONT_SMALL.getHeight() > imgStartH) {
                            img_h = (Constant.FONT_SMALL.getHeight() - imgStartH) / 2;
                        }
                        g.drawRegion(img, imgStartX + img_W, imgStartY, imgStartW,
                                imgStartH, Constant.TRANS_NONE, iStartX, iStartY + img_h, 0);
                    }
//                    if(imgitem!=null){
//                        g.drawImage(imgitem, iStartX, iStartY, 0);
//                    }
                    tempLength = tempLength + imgStartW - charTwo;
                    iStartX = iStartX + imgStartW - charTwo;
                } else if (tempChar1 == '%') {
                    //去掉图片显示
                    int charTwo = Constant.FONT_SMALL.stringWidth("/%5");
//                    int charTwo = 0;
                    if (tempChar1 == '%') {
                        if (imgId != null) {//去掉图片显示
//                            if (imgId.length() > 1) {
//                                charTwo = Constant.FONT_SMALL.stringWidth("/%5");
//                            } else {
//                                charTwo = Constant.FONT_SMALL.stringWidth("/%5") + 30;
//                            }
                        }
                    } else {
                        if (imgId != null) {//去掉图片显示
//                            if (imgId.length() > 1) {
//                                charTwo = Constant.FONT_SMALL.stringWidth("/15");
//                            } else {
//                                charTwo = Constant.FONT_SMALL.stringWidth("/15") + 30;
//                            }
                        }
                    }
                    if (tempChar1 == '%') {
                        colnum = i;
                    }
                    bldrawchar = false;
                    bydrawCount = 0;
                    if (imgitem != null) {//去掉图片显示
//                        g.drawImage(imgitem, iStartX, iStartY - 4, 0);
                    }
                    //去掉图片显示
                    tempLength = tempLength - charTwo;
                    iStartX = iStartX - charTwo;
//                    tempLength = tempLength + 30 - charTwo;
//                    iStartX = iStartX + 30 - charTwo;
                }
            }
            charWidth = Constant.FONT_SMALL.charWidth(tempChar);
            if (bldrawchar) {
                g.setColor(iShadowColor);
                //#if NOKIA_S60V5 || NOKIA_S40V3 || NOKIAN73  || NORMAL_240_400 || MOT0 || K790
                 g.drawChar(tempChar, iStartX, iStartY, 0);
                //#else
//#                g.drawChar(tempChar, iStartX - 1, iStartY, 0);
//#                g.drawChar(tempChar, iStartX + 1, iStartY, 0);
//#                g.drawChar(tempChar, iStartX, iStartY - 1, 0);
//#                g.drawChar(tempChar, iStartX, iStartY + 1, 0);
                //#endif

                g.setColor(iFontColor);
                if (colstr != null && colnum != -1) {
                    if ((i > colnum + 1) && (i < colnum + 2 + colstr.length())) {
//                        Tools.printLog("colstr   ::  "+colstr);
                        int coltype = Integer.parseInt(colstr.substring(0, 1));
                        int col = 0xFFFFFF;
                        switch (coltype) {
                            case 1:
                                col = 0xffffff;
                                break;
                            case 2:
                                col = 0x00ff33;
                                break;
                            case 3:
                                col = 0x33b1fa;
                                break;
                            case 4:
                                col = 0xff00ff;
                                break;
                            case 5:
                                col = 0xff9900;
                                break;
                            case 6:
                                col = 0x00ccff;
                                break;
                            case 9:
                                col = 0x999999;
                                break;
                            default:
                                col = 0xFFFFFF;
                                break;
                        }
                        g.setColor(col);
                    }
                } else if (colnumStr && colnum1 != -1) {
                    if (i < colnum1) {
//                        g.setColor(0xff0000);
                        int coltype = Integer.parseInt(colstr.substring(0, 1));
                        int col = 0xFFFFFF;
                        switch (coltype) {
                            case 1:
                                col = 0xffffff;
                                break;
                            case 2:
                                col = 0x00ff33;
                                break;
                            case 3:
                                col = 0x33b1fa;
                                break;
                            case 4:
                                col = 0xff00ff;
                                break;
                            case 5:
                                col = 0xff9900;
                                break;
                            case 9:
                                col = 0x999999;
                                break;
                            default:
                                col = 0xFFFFFF;
                                break;
                        }
                        g.setColor(col);
                    }
                }
                g.drawChar(tempChar, iStartX, iStartY, 0);
            } else {
                bydrawCount += 1;
                if (bydrawCount == 3) {
                    bldrawchar = true;
                }
            }
            tempLength = tempLength + charWidth;
            iStartX = iStartX + charWidth;
        }
    }

    /**
     * 绘制圆角矩形
     * @param g
     * @param img
     * @param imgx
     * @param imgy
     * @param imgwidth
     * @param imgheight
     * @param x_dest
     * @param y_dest
     * @param fill_h
     * @param color
     */
    public static void drawNewFillRect(Graphics g, Image img, int imgx, int imgy, int imgwidth, int imgheight, int x_dest, int y_dest, int fill_h, int color) {
        //绘制角
        g.drawRegion(img, 0, 0, imgwidth, imgheight, Constant.TRANS_NONE, x_dest, y_dest, 0); //左上角
        g.drawRegion(img, imgx, 0, imgwidth, imgheight, Constant.TRANS_NONE,
                Constant.SCREEN_WIDTH - x_dest, y_dest, g.RIGHT | g.TOP);//右上角
        g.drawRegion(img, 0, imgy, imgwidth, imgheight, Constant.TRANS_NONE,
                x_dest, y_dest + fill_h - imgheight, g.LEFT | g.TOP); //左下角
        g.drawRegion(img, imgx, imgy, imgwidth, imgheight, Constant.TRANS_NONE,
                Constant.SCREEN_WIDTH - x_dest, y_dest + fill_h - imgheight, g.RIGHT | g.TOP);//右下角
        //绘制四条
        g.setColor(color);
        g.fillRect(x_dest + imgwidth, y_dest, Constant.SCREEN_WIDTH - (x_dest + imgwidth) * 2, imgheight);//上条
        g.fillRect(x_dest + imgwidth, y_dest + fill_h - imgheight,
                Constant.SCREEN_WIDTH - (x_dest + imgwidth) * 2, imgheight);//下条
        g.fillRect(x_dest, y_dest + imgheight, imgheight, fill_h - imgheight * 2);//左条
        g.fillRect(Constant.SCREEN_WIDTH - x_dest - imgwidth, y_dest + imgheight, imgwidth, fill_h - imgheight * 2);//右条
        g.fillRect(x_dest, y_dest + imgheight, Constant.SCREEN_WIDTH - x_dest * 2, fill_h - imgheight * 2);//背景
    }
    /*
     * 获得指定标签中的字符串
     */
    private static int iNetKeyNums = 0;
    
    public static String getNetKey(String strContent, int nums) {
        iNetKeyNums = 0;
        int length = strContent.length();
        char tempChar;
        for (int i = 0; i < length; i++) {
            tempChar = strContent.charAt(i);
            if (tempChar == '&') {
                if (strContent.charAt(i + 1) == 'g') {
//                strContent =  strContent.substring(i+1);
                    for (int j = i + 4; j < length; j++) {
                        tempChar = strContent.charAt(j);
                        if (tempChar == '&') {
                            //没有数据跳过
                            if (j == i + 4) {
                                break;
                            }
                            if (iNetKeyNums == nums) {
                                strContent = strContent.substring(i + 4, j);
//                      Tools.printLog("strContentstrContentstrContent"+strContent);
                                return strContent;
                            } else {
                                iNetKeyNums += 1;
                                break;
                            }
                        }
                    }
                }
            }
        }
        return null;
    }
    /*
     * 打印log
     */
    
    public static void printLog(String log) {
        if (Constant.DEBUG) {
            System.out.println(log);
        }
    }

    /**
     * 用实现绘制图片
     */
    public static void drawImage(Graphics graphics, Image image, int x_image, int y_image, int anchor) {
        //#if NOKIA=="TRUE"    
//#         DirectUtils.getDirectGraphics(graphics).drawImage(image, x_image, y_image, anchor, 0);
        //#else 
        graphics.drawImage(image, x_image, y_image, anchor);
        //#endif
    }

    /**
     * 用实现绘制图片局部区域
     */
    public static void drawRegion(Image image, int x_src, int y_src, int width, int height, int transform,
            int x_dest, int y_dest, int anchor, Graphics graphics) {
        //#if NOKIA=="TRUE"    
//#         drawRegionNokia(image, x_src, y_src, width, height, transform, x_dest, y_dest, anchor, graphics);
        //#else 
        graphics.drawRegion(image, x_src, y_src, width, height, transform, x_dest, y_dest, Graphics.LEFT | Graphics.TOP);
        //#endif
    }

    /**
     * 用NokiaUI实现绘制图片的局部区域
     * @param image Image 图片
     * @param x_src int 源图x
     * @param y_src int 源图y
     * @param width int 源图宽
     * @param height int 源图高
     * @param transform int 翻转信息
     * @param x_dest int 绘制x位置
     * @param y_dest int 绘制y位置
     * @param anchor int 锚点
     * @param graphics Graphics 画笔
     */
    private static void drawRegionNokia(Image image, int x_src, int y_src, int width, int height, int transform,
            int x_dest, int y_dest, int anchor, Graphics graphics) {
        int x_image = x_dest;
        int y_image = y_dest;
        switch (transform) {
            case Constant.TRANS_NONE:
                transform = 0;
                x_image -= x_src;
                y_image -= y_src;
                break;
            case Constant.TRANS_MIRROR:
                transform = 0x2000;
                x_image -= image.getWidth() - x_src - width;
                y_image -= y_src;
                break;
            case Constant.TRANS_MIRROR_ROT90:
                transform = 0x2000 | 90;
                x_image -= image.getHeight() - y_src - height;
                y_image -= x_src;
                break;
            case Constant.TRANS_MIRROR_ROT180:
                transform = 0x4000;
                x_image -= x_src;
                y_image -= image.getHeight() - y_src - height;
                break;
            case Constant.TRANS_MIRROR_ROT270:
                transform = 0x2000 | 270;
                x_image -= y_src;
                y_image -= x_src;
                break;
            case Constant.TRANS_ROT90:
                transform = 270;
                x_image -= image.getHeight() - y_src - height;
                y_image -= x_src;
                break;
            case Constant.TRANS_ROT180:
                transform = 180;
                x_image -= image.getWidth() - x_src - width;
                y_image -= image.getHeight() - y_src - height;
                break;
            case Constant.TRANS_ROT270:
                transform = 90;
                x_image -= y_src;
                y_image -= image.getWidth() - x_src - width;
                break;
        }
        graphics.setClip(x_dest, y_dest, width, height);
        //#if NOKIA=="TRUE"  
//#         DirectUtils.getDirectGraphics(graphics).drawImage(image, x_image, y_image, anchor, transform);
//#endif

        graphics.setClip(0, 0, Constant.SCREEN_WIDTH, Constant.SCREEN_HEIGHT);
    }
    /**
     * 通过索引值获得装备属性的
     * @param byAttributeIndex 
     */
    public static String[] sEquipAttributeName = null;
    
    public static String getEquipAttributeNick(byte byAttributeIndex) {
        if (Tools.sEquipAttributeName == null) {
            //Tools.sEquipAttributeName = new String[]{"臂力", "体魄", "气力", "敏捷", "悟性", "幸运", "速度", "冰攻击", "火攻击", "毒攻击", "冰抗性", "火抗性", "毒抗性", "冰防", "火防", "毒防", "冰触", "火触", "毒触", "冷却时间", "攻击力", "防御力", "生命上限", "精气上限", "生命恢复", "精力回复", "闪避", "命中"};
//            byte[] byBaseAttribute = new byte[]{20, 7, 8, 9, 21, 13, 14, 15};
//            byte[] byOtherAttribute = new byte[]{0, 1, 2, 3, 4, 27, 26, 22, 23, 24, 25, 10, 11, 12, 5, 6, 16, 17, 18, 19};
            Tools.sEquipAttributeName = new String[]{"臂力", "体魄", "气力", "敏捷", "幸运", "速度", "生命上限", "精气上限", "攻击力", "冰攻击", "火攻击", "毒攻击", "防御力", "冰防御", "火防御", "毒防御", "冰抗性", "毒抗性", "火抗性", "闪避", "命中", "生命恢复", "精力回复", "悟性", "冰触", "火触", "毒触", "冷却时间", "经验获得速度", "修为获得速度"};
        }
        if (byAttributeIndex >= Tools.sEquipAttributeName.length) {
            return "";
        } else {
            return sEquipAttributeName[byAttributeIndex];
        }
    }
    
    public static void clearEquipAttributeArray() {
        Tools.sEquipAttributeName = null;
    }
    
    public static String byteConvert(long lByteNum) {
        String flow = "";
        if (lByteNum >= 1048567) {
            flow += String.valueOf(lByteNum / 1048567) + "M";
            lByteNum = lByteNum % 1048567;
        }
        if (lByteNum >= 1024) {
            flow += String.valueOf(lByteNum / 1024) + "K";
            lByteNum = lByteNum % 1024;
        }
        flow += lByteNum + "B";
        return flow;
    }
    /*
     * 获得从当前点到目标点的距离的平方
     */
    
    public static int getDistance(int srcx, int srcy, int objx, int objy) {
        return ((srcx - objx) * (srcx - objx) + (srcy - objy) * (srcy - objy));
    }

    /**
     * 屏蔽KE模拟器看图
     */
    public void dummy() {
        System.out.println("Hack KEmulator (Disable memory view)");
    }
    
    public boolean equals(Object obj) {
        System.out.println((1 / 0));
        return false;
    }

    /***
     * 检测用户输入的字符串是否合法
     */
    public static byte checkStringLegal(String sWord, int minLength, int maxLength) {
        if (sWord == null || sWord.length() == 0 || (sWord.length() < minLength || sWord.length() > maxLength)) {
            return 1;
        }
        String Illegal = "\"|?><.,:;/*&^%$#@!~`\\“”‘’|、-_=+";
        for (short i = 0; i < sWord.length(); i++) {
            if (Illegal.indexOf(sWord.charAt(i)) != -1) {
                return 2;
            }
        }
        return 0;
    }

    /**
     * @param bbyQuickToRoam 是否直接退到漫游界面
     * @param byLeft  (1,左软键，2，右软键)
     * @param state 返回的界面状态
     * @param index  子索引
     */
    public static void openRoamMenu(boolean bQuickToRoam, byte byLeft, byte state, int index) {
        if (MainLogic.getInstance().byQuickToRoam) {
            MainLogic.getInstance().byQuickToRoam = false;
            MainLogic.getInstance().pushState(Constant.GAME_UI_ROAM, true);
        } else if (bQuickToRoam) {
            MainLogic.getInstance().pushState(Constant.GAME_UI_ROAM, true);
        } else {
            MainLogic.getInstance().pushState(Constant.GAME_UI_ROAM_MENU, true);
            MainLogic.getInstance().uiInterFace.setMenu(byLeft, state, index);
        }
    }
    //#if NOKIA_E72
//#     public static Image[] barImage;
//#     public static int iBarPlace;
//# 
//#     public static void initE72ScollBar() {
//#         iBarPlace = 0;
//#         MainLogic.getInstance().uiInterFace.iScreenOffsetH = 0;
//#         Tools.barImage = new Image[3];
//#         Tools.barImage[0] = ResManager.createImage(90000112);
//#         Tools.barImage[1] = ResManager.createImage(90000110);
//#         Tools.barImage[2] = ResManager.createImage(90000111);
//# 
//#     }
//# 
//#     public static void updateE72ScollBar(int iScreenOffsetH) {
//#         if (iScreenOffsetH >= 0) {
//#             MainLogic.getInstance().uiInterFace.iScreenOffsetH = 0;
//#             Tools.iBarPlace = 0;
//#         } else if (iScreenOffsetH <= -80) {
//#             MainLogic.getInstance().uiInterFace.iScreenOffsetH = -80;
//#             Tools.iBarPlace = 164;
//#         } else {
//#             MainLogic.getInstance().uiInterFace.iScreenOffsetH = iScreenOffsetH;
//#             Tools.iBarPlace = 164 * iScreenOffsetH / -80;
//#         }
//#     }
//# 
//#     public static void clearE72ScollBar() {
//#         Tools.barImage = null;
//#         Tools.iBarPlace = 0;
//#         MainLogic.getInstance().uiInterFace.iScreenOffsetH = 0;
//#     }
//# 
//#     /**
//#      * 绘制e72滚动条
//#      * @param barHead 滚动条图片头尾
//#      * @param barLine 滚动条中间拼接的部分
//#      * @param barMark  位置标志
//#      * @param barPlace  滚动的位置(0-164)
//#      */
//#     public static void drawE72ScrollBar(Graphics g) {
//#         //绘制头
//#         g.drawImage(Tools.barImage[0], Constant.UI_START_X + 291, Constant.UI_START_Y + 25, 0);
//#         //绘制尾部
//#         g.drawImage(Tools.barImage[0], Constant.UI_START_X + 291, Constant.UI_START_Y + 214, 0);
//#         //绘制中间
//#         Tools.drawTilePic(g, (byte) 2, Constant.UI_START_X + 292, Constant.UI_START_Y + 32, 182, Tools.barImage[1], 0, 0, 5, 20, Constant.TRANS_NONE);
//#         //绘制滚动位置
//#         g.drawImage(Tools.barImage[2], Constant.UI_START_X + 288, Constant.UI_START_Y + 32 + Tools.iBarPlace, 0);
//#     }
    //#endif

    /**
     * 绘制弹出tips
     * @param g
     * @param sDesc
     * @param startX 物品开始位置
     * @param startY 
     * @param width 高度
     * @param height  宽度
     */
    public static void drawItemsPop(Graphics g, String sDesc, int startX, int startY, int width, int height) {
        //#if NOKIA_S60V5
         byte byOffset = 30;
        //#else
//#        byte byOffset = 20;
        //#endif
        startX += byOffset;
        startY += byOffset;
        if (startX + width > Constant.UI_START_X + Constant.DRAW_WIDTH) {
            startX = Constant.UI_START_X + Constant.DRAW_WIDTH - width;
        }
        if (startY + height > Constant.UI_START_Y + Constant.DRAW_HEIGHT) {
            startY = Constant.UI_START_Y + Constant.DRAW_HEIGHT - height;
        }
        g.setColor(0x999999);
        g.fillRoundRect(startX, startY, width, height, 7, 7);
        g.setColor(0x000000);
        g.drawRoundRect(startX, startY, width, height, 7, 7);
        Tools.drawParagraph(g, startX + 5, startY + 5, width - 5, sDesc, 0xFFFFFF, Constant.FONT_SMALL_HEIGHT, -1);
        
    }
    
    public static void drawItemsPop(Graphics g, String sDesc, int startX, int startY, int width, int height, Image ingotPic, int ingotPicStart) {
        //#if NOKIA_S60V5
         byte byOffset = 30;
        //#else
//#        byte byOffset = 20;
        //#endif
        startX += byOffset;
        startY += byOffset;
        if (startX + width > Constant.UI_START_X + Constant.DRAW_WIDTH) {
            startX = Constant.UI_START_X + Constant.DRAW_WIDTH - width;
        }
        if (startY + height > Constant.UI_START_Y + Constant.DRAW_HEIGHT) {
            startY = Constant.UI_START_Y + Constant.DRAW_HEIGHT - height;
        }
        g.setColor(0x999999);
        g.fillRoundRect(startX, startY, width, height, 7, 7);
        g.setColor(0x000000);
        g.drawRoundRect(startX, startY, width, height, 7, 7);
        Tools.drawParagraph(g, startX + 5, startY + 5, width - 10, sDesc, 0xFFFFFF, Constant.FONT_SMALL_HEIGHT, -1);
        if (ingotPic != null) {
            g.drawImage(ingotPic, startX + ingotPicStart, startY + height - 5 - Constant.FONT_SMALL_HEIGHT + ((Constant.FONT_SMALL_HEIGHT - 15) >> 1), 0);
        }
        
    }
    
    public static String getGoodsNameDesc(String name, byte byColor, short shLevel) {
        return "<" + Tools.getColorReplaceLetter(Goods.getGoodsNameColor(byColor)) + name + ">" + (shLevel > 0 ? "|等级:" + shLevel : "");
    }
    
    public static void drawPriceInput(Graphics g, int startX, int startY, int gold, byte silver, byte copper, boolean bShowFlash, byte byFlashPlace, Image word) {
        g.setColor(0x000000);
        int h = 16 + (Constant.FONT_SMALL_HEIGHT << 3);
        int w = Constant.FONT_CHAR_WIDTH * 8;
        if (startX + w > Constant.UI_START_X + Constant.DRAW_WIDTH) {
            startX = Constant.UI_START_X + Constant.DRAW_WIDTH - w - 2;
        }
        if (startY + h > Constant.UI_START_Y + Constant.DRAW_HEIGHT) {
            startY = Constant.UI_START_Y + Constant.DRAW_HEIGHT - h - 2;
        }
        g.fillRect(startX, startY, Constant.FONT_CHAR_WIDTH * 8, h);
        startX = startX + 5;
        startY += 5;
        g.setColor(0xFFFFFF);
        g.drawString("货物单价：", startX, startY, Graphics.LEFT | Graphics.TOP);
        startY += Constant.FONT_SMALL_HEIGHT;
        g.drawString("（    ）", startX, startY, Graphics.LEFT | Graphics.TOP);
        g.setColor(0xffff00);
        g.drawString("金", startX + Constant.FONT_CHAR_WIDTH, startY, Graphics.LEFT | Graphics.TOP);
        g.setColor(0xFFFFFF);
        startY += Constant.FONT_SMALL_HEIGHT;
        g.drawRect(startX, startY, Constant.FONT_CHAR_WIDTH * 6, Constant.FONT_SMALL_HEIGHT + 2);
        if (gold >= 0) {
            g.drawString(String.valueOf(gold), startX + 2, startY + 2, 0);
        }
        if (bShowFlash && byFlashPlace == 1) {
            g.drawChar('|', startX + 2 + (gold >= 0 ? Constant.FONT_SMALL.stringWidth(String.valueOf(gold)) + 1 : 0), startY + 2, 0);
        }
        startY += Constant.FONT_SMALL_HEIGHT + 2;
        g.drawString("（银）", startX, startY, Graphics.LEFT | Graphics.TOP);
        startY += Constant.FONT_SMALL_HEIGHT;
        g.drawRect(startX, startY, Constant.FONT_CHAR_WIDTH * 6, Constant.FONT_SMALL_HEIGHT + 2);
        if (silver >= 0) {
            g.drawString(String.valueOf(silver), startX + 2, startY + 2, 0);
        }
        if (bShowFlash && byFlashPlace == 2) {
            g.drawChar('|', startX + 2 + (silver >= 0 ? Constant.FONT_SMALL.stringWidth(String.valueOf(silver)) + 1 : 0), startY + 2, 0);
        }
        startY += Constant.FONT_SMALL_HEIGHT + 2;
        g.drawString("（    ）", startX, startY, Graphics.LEFT | Graphics.TOP);
        g.setColor(0x9b7a2b);
        g.drawString("铜", startX + Constant.FONT_CHAR_WIDTH, startY, Graphics.LEFT | Graphics.TOP);
        g.setColor(0xFFFFFF);
        
        startY += Constant.FONT_SMALL_HEIGHT;
        g.drawRect(startX, startY, Constant.FONT_CHAR_WIDTH * 6, Constant.FONT_SMALL_HEIGHT + 2);
        if (copper >= 0) {
            g.drawString(String.valueOf(copper), startX + 2, startY + 2, 0);
        }
        if (bShowFlash && byFlashPlace == 3) {
            g.drawChar('|', startX + 2 + (copper >= 0 ? Constant.FONT_SMALL.stringWidth(String.valueOf(copper)) + 1 : 0), startY + 2, 0);
        }
        startY += Constant.FONT_SMALL_HEIGHT + 8;
        //this.imgArray[3], 49, 0, 23, 12
        if (word != null) {
            g.drawRegion(word, 0, 0, 24, 12, Constant.TRANS_NONE, startX, startY, 0);
            g.drawRegion(word, 49, 0, 23, 12, Constant.TRANS_NONE, startX + w - 15 - 23, startY, 0);
        }
        
    }
    /*
     * 根据long值获得时间 分 秒
     */
    
    public static int getTime(long timestr, byte type) {
        switch (type) {
            case 0://分
//                timestr
                break;
            case 1://秒
                break;
        }
        return -1;
    }
    /*
     * 程序绘制的框
     */
    
    public static void drawRectBox(Graphics g, int x, int y, int w, int h, int colorBG, int colorrect1) {
        g.setColor(colorBG);
        g.fillRect(x, y, w, h);
        g.setColor(colorrect1);
        g.fillRect(x + 1, y + 1, w - 2, h - 2);
        g.setColor(colorBG);
        g.fillRect(x + 2, y + 2, w - 4, h - 4);
    }
    
    public static void drawTextArea(Graphics g, String str, int fontColorbg, int fontColorshadow, int x, int y, int w, int h, int colorBG, int colorrect1) {
        g.setClip(x, y, w, h);
        drawRectBox(g, x, y, w, h, colorBG, colorrect1);
        drawParagraph(g, x + 6, y + 6, w - 12, str, fontColorbg, 20, fontColorshadow);
        g.setClip(0, 0, Constant.SCREEN_WIDTH, Constant.SCREEN_HEIGHT);
    }

    /**
     * 将称号的ID转为名称
     */
    public static String nickIDToName(byte byNickID) {
        switch (byNickID) {
            case 1:
                return "神之最强";
            case 2:
                return "最强勇士";
            case 3:
                return "最强女神";
            case 4:
                return "最强武师";
            case 5:
                return "最强刺客";
            case 6:
                return "最强术士";
            case 7:
                return "富可敌国";
            case 8:
                return "豪门少爷";
            case 9:
                return "巅峰富婆";
            case 10:
                return "杀戮之神";
            case 11:
                return "修罗魔神";
            case 12:
                return "罗刹杀神";
            case 13:
                return "天下第一帮主";
            case 14:
                return "天下第一帮众";
            default:
                return "";
            
        }
    }
    
    public static void drawPackageBox(Graphics g, Image img, int startX, int startY, byte iState, int imgW, int imgH) {
        g.drawImage(img, startX, startY, 0);
        g.drawRegion(img, 0, 0, imgW, imgH, Constant.TRANS_MIRROR, startX + imgW, startY, 0);
        g.drawRegion(img, 0, 0, imgW, imgH, Constant.TRANS_MIRROR_ROT180, startX, startY + imgH, 0);
        g.drawRegion(img, 0, 0, imgW, imgH, Constant.TRANS_ROT180, startX + imgW, startY + imgH, 0);
        if (iState == 1) {
            //当前格子不可用
            g.setColor(0x000000);
            g.drawLine(startX, startY, startX + imgW * 2 - 1, startY + imgH * 2 - 1);
            g.drawLine(startX + imgW * 2 - 1, startY, startX, startY + imgH * 2 - 1);
        }
    }

    /**
     * 分割字符串
     * @param original  原始的字符串
     * @param regex  分割的字符
     * @return  字符串数组
     */
    public static String[] splitString(String original, String regex) {
//        System.out.println(original);
        //　取子串的起始位置
        int startIndex = 0;
        //将结果数据先放入Vector中
        Vector v = new Vector();
        //返回的结果字符串数组
        String[] str = null;
        //存储取子串时起始位置
        int index = 0;
        //获得匹配子串的位置
        startIndex = original.indexOf(regex);
        //如果起始字符串的位置小于字符串的长度，则证明没有取到字符串末尾。
        //-1代表取到了末尾
        if (startIndex != -1) {
            String temp;
            while (startIndex < original.length() && startIndex != -1) {
                temp = original.substring(index, startIndex);
                //取子串
                v.addElement(temp);
                //设置取子串的起始位置
                index = startIndex + regex.length();
                //获得匹配子串的位置
                startIndex = original.indexOf(regex, startIndex + regex.length());
            }
            temp = null;
            //取结束的子串
            v.addElement(original.substring(index));
        } else {
            v.addElement(original);
        }
        //将Vector对象转换成数组
        str = new String[v.size()];
        for (int i = 0; i < v.size(); i++) {
            str[i] = (String) v.elementAt(i);
//            System.out.println(str[i]);
        }
        v = null;
        //返回生成的数组
        return str;
    }

    /**
     * downloadAddress 用户中心返回的下载地址
     */
    public static String getJarDownloadUrl(String downloadAddress) {
        return downloadAddress + Constant.JAD_URL + Constant.QUDAO_NAME + ".jad";
    }

    /**
     * 生成连接服务器的Ip和端口
     * @param ip
     * @param port
     * @param authCode1
     * @param authCode2 
     */
    public static void makeConnectIP(String ip, String port, int authCode1, int authCode2) {
//        Constant.CONNECT_IP = Constant.IP_HEAD + ip + ":" + port;
//        Constant.AUTH_CODE = authCode1;
//        Constant.AUTH_CODE2 = authCode2;
    }

    /**
     * 获得手机唯一标识码
     * @return 
     */
    public static void getMobileImei() {
        //获取到imei号码
        GameBean.STR_MOBILE_IMEI = "unkown";
        Rms.loadGame(Constant.RMS_MOBILE_IMEI);
        if (GameBean.STR_MOBILE_IMEI != null && !GameBean.STR_MOBILE_IMEI.equals("")) {
            return;
        }
        GameBean.STR_MOBILE_IMEI = System.getProperty("com.nokia.IMEI");
        if (GameBean.STR_MOBILE_IMEI == null || "".equals(GameBean.STR_MOBILE_IMEI)) {
            GameBean.STR_MOBILE_IMEI = System.getProperty("com.nokia.mid.imei");
        }
        if (GameBean.STR_MOBILE_IMEI == null || "".equals(GameBean.STR_MOBILE_IMEI)) {
            GameBean.STR_MOBILE_IMEI = System.getProperty("com.nokia.IMEI");
        }
        if (GameBean.STR_MOBILE_IMEI == null || "".equals(GameBean.STR_MOBILE_IMEI)) {
            GameBean.STR_MOBILE_IMEI = System.getProperty("com.sonyericsson.imei");
        }
        
        if (GameBean.STR_MOBILE_IMEI == null || "".equals(GameBean.STR_MOBILE_IMEI)) {
            GameBean.STR_MOBILE_IMEI = System.getProperty("phone.imei");
        }
        if (GameBean.STR_MOBILE_IMEI == null || "".equals(GameBean.STR_MOBILE_IMEI)) {
            GameBean.STR_MOBILE_IMEI = System.getProperty("com.siemens.imei");
        }
        if (GameBean.STR_MOBILE_IMEI == null || "".equals(GameBean.STR_MOBILE_IMEI)) {
            GameBean.STR_MOBILE_IMEI = System.getProperty("com.motorola.IMEI");
        }
        if (GameBean.STR_MOBILE_IMEI == null || "".equals(GameBean.STR_MOBILE_IMEI)) {
            GameBean.STR_MOBILE_IMEI = System.getProperty("com.samsung.imei");
        }
        if (GameBean.STR_MOBILE_IMEI == null || "".equals(GameBean.STR_MOBILE_IMEI)) {
            GameBean.STR_MOBILE_IMEI = System.getProperty("IMEI");
        }
        if (GameBean.STR_MOBILE_IMEI == null || "".equals(GameBean.STR_MOBILE_IMEI)) {
            GameBean.STR_MOBILE_IMEI = String.valueOf(System.currentTimeMillis());
        }
        Rms.saveGame(Constant.RMS_MOBILE_IMEI, null);
    }
    /*
     * 获得手机类型
     */
    
    public static String getMobileType() {
        return System.getProperty("microedition.platform");
    }
    
    public static void quitToSetNetConnect() {
        GameBean.I_SYSTEM_MESSAGE_TYPE = 6;
        LocalMsgManager.getInstance().clearHttpConnect();
        MainLogic.getInstance().pushState(Constant.GAME_UI_OPTION_LIST, true);
        MainLogic.getInstance().uiInterFace.sysMessage.showMessage("提示", "网络连接失败!,请检查您的网络是否正确");
    }
}
